2020-06-17 12:19 AM
I develop stm8 using cosmic compiler and v.2.3.1 standard libary.
I think there is a problem with the definition of CAN_ReceiveAll.
In this function I can get an address of _Data variable.
But, I can not get the address in Caller side.
My thoughts should be defined as:
---Caller Side---
uint8_t *pData;
CAN_ReceiveAll(&id, &pData);
--CAN_ReceiveAll Definition-- (Bold is modified)
void CAN_ReceiveAll(uint32_t* pid, uint8_t** pdata)
{
CAN_Page_TypeDef can_page = CAN_GetSelectedPage();
uint32_t temp1 = 0, temp2 = 0, temp3 = 0;
/* select Fifo page*/
CAN->PSR = CAN_Page_RxFifo;
/* Get the Id */
_IDE = (uint8_t)(CAN->Page.RxFIFO.MIDR1 & CAN_Id_Extended);
if (_IDE != CAN_Id_Standard)
{
temp1 = ((uint32_t)((uint32_t)CAN->Page.RxFIFO.MIDR3) << 8);
temp2 = ((uint32_t)((uint32_t)CAN->Page.RxFIFO.MIDR2) << 16);
temp3 = ((uint32_t)((uint32_t)CAN->Page.RxFIFO.MIDR1 & 0x1F) << 24);
*pid = (uint32_t)CAN_EXTID_SIZE & ((CAN->Page.RxFIFO.MIDR4) | temp1 | temp2 | temp3 );
}
else
{
temp1 = (uint16_t)((uint16_t)((uint16_t)((uint16_t)CAN->Page.RxFIFO.MIDR1 & 0x1F) << 6));
temp2 = (uint16_t)((uint16_t)((uint16_t)CAN->Page.RxFIFO.MIDR2 >> 2)&0x3F);
*pid = (uint16_t)CAN_STDID_SIZE & (temp1 | temp2 );
}
_RTR = (uint8_t)((uint8_t)0x20 & CAN->Page.RxFIFO.MIDR1);
/* Get the DLC */
_DLC = (uint8_t)(CAN->Page.RxFIFO.MDLCR & (uint8_t)0x0F);
/* Get the FMI */
_FMI = CAN->Page.RxFIFO.MFMI;
/* Get the data field */
_Data[0] = CAN->Page.RxFIFO.MDAR1;
_Data[1] = CAN->Page.RxFIFO.MDAR2;
_Data[2] = CAN->Page.RxFIFO.MDAR3;
_Data[3] = CAN->Page.RxFIFO.MDAR4;
_Data[4] = CAN->Page.RxFIFO.MDAR5;
_Data[5] = CAN->Page.RxFIFO.MDAR6;
_Data[6] = CAN->Page.RxFIFO.MDAR7;
_Data[7] = CAN->Page.RxFIFO.MDAR8;
*pdata = _Data;
/* Release the FIFO */
CAN_FIFORelease();
/*Restore Last Page*/
CAN_SelectPage(can_page);
}
If I am using the API incorrectly, please advise.