| ??? 01/25/08 23:09 Read: times |
#149963 - Question - Why does the example code work? Responding to: ???'s previous message |
Hi Werner, I read your post with interest as I to am using the f040 with CAN, I looked up the C_CAN user manual as well to see what you were actually doing.
I assume that from your main loop (or a timer or repitive processes) you are constantly calling your function receive_data, as you stated that you are not using interrupts. the user manual on page 19 states 3.3.1 IFx Command Request Registers A message transfer is started as soon as the CPU has written the message number to the Command Request Register. With this write operation the Busy bit is automatically set to ‘1’ and signal CAN_WAIT_B is pulled LOW to notify the CPU that a transfer is in progress. After a wait time of 3 to 6 CAN_CLK periods, the transfer between the Interface Register and the Message RAM has completed. The Busy bit is set back to zero and CAN_WAIT_B is set back to HIGH (see figure 5.2 on page 44). Busy Busy Flag one set to one when writing to the IFx Command Request Register zero reset to zero when read/write action has finished. Message Number 0x01-0x20 Valid Message Number, the Message Object in the Message RAM is selected for data transfer. 0x00 Not a valid Message Number, interpreted as 0x20. 0x21-0x3F Not a valid Message Number, interpreted as 0x01-0x1F. Note: When a Message Number that is not valid is written into the Command Request Register, the Message Number will be transformed into a valid value and that Message Object will be transferred. So you hanging around here while (CAN0DATH > 0x7f); // wait for busy to go away ! makes perfect sense, according to the user manual. What I don't understand is why the example code works at all without waiting for this busy flag to clear. for instance my code which is largely untouched from the example code does this
// Receive Data from the IF2 buffer
void receive_data (char MsgNum)
{
unsigned int data1;
unsigned int data2;
SFRPAGE = CAN0_PAGE; // IF1 already set up for RX
CAN0ADR = IF2CMDRQST;// Point to Command Request Reg.
CAN0DATL = MsgNum; // Move new data for RX from Msg Obj "MsgNum"
CAN0ADR = IF2ARB1;
gui_arbt1 = CAN0DAT;
gui_arbt2 = CAN0DAT;
so according to the user manual (and your experience) I should be waiting for the busy flag to clear after writing to IF2CMDRQST. I still have CAN interrupts running here as well so perhaps this is protecting me??? Any thoughts, it's easy enough to add one line similiar to what you have done. the question is why? Regards Marshall Brown |
| Topic | Author | Date |
| CAN bus: losing Messages on Silabs F040 | 01/01/70 00:00 | |
| Problem solved | 01/01/70 00:00 | |
| Question - Why does the example code work? | 01/01/70 00:00 | |
Why does it work | 01/01/70 00:00 |



