If I have 32 sets of data, how to use the CAN, once the data sent out 。
NOW I want to send 8 bytes of data,There are 32 sets of such data;So call the function (Transmit_Message_1) 32 times。BUT ’I think it's too long to wait;A lot of time wasted in this statement(while (CAN_0.MB[1].CS.B.CODE != 0x8););So now, I would like to put 32 data in different BUFFER inside。Such as MB [0] -MB [31],And then send the data together。My purpose is to reduce the sending function to send the completion time, in order to allow the processor to do other things.My leader told me that the data inside the MB is very fast, the time is mainly wasted here(while (CAN_0.MB[1].CS.B.CODE != 0x8);)So how can i improve this code?I can solve this problem from which part of the reference manual。
Solved! Go to Solution.
Hello,
from my point of view, it is not necessary to wait until the message is sent from message buffer. Use for example FOR loop. In the FOR loop, fill MB0 and set code to 0xC, fill MB1 and set code to 0xC and so on.
To check, if MB was successfully transmitted, you can use for example interrupt. Another way is check message buffer status as soon as you will fill it again. The method you use is strictly dependent on your application requirements.
Regards,
Martin
1. If You want to use only one MB, it is necesser to wait until end of sending. But the way You implemented is passive waiting. Use active waiting, means dont go in to loop but let the code go and check BUSY flag activelly.
2. better slution is to use more then one MBs, just fill one after another and mark to send same time.
Hello,
I am not sure if I understand your question correct. Could you please clarify your requirement? Which microcontroller you use?
Regards,
Martin
hi, Martin Kovar;
the MCU is MPC5775K;
NOW I want to send 8 bytes of data,There are 32 sets of such data;So call the function (Transmit_Message_1) 32 times。BUT ’I think it's too long to wait;A lot of time wasted in this statement(while (CAN_0.MB[1].CS.B.CODE != 0x8););So now, I would like to put 32 data in different BUFFER inside。Such as MB [0] -MB [31],And then send the data together。My purpose is to reduce the sending function to send the completion time, in order to allow the processor to do other things.My leader told me that the data inside the MB is very fast, the time is mainly wasted here(while (CAN_0.MB[1].CS.B.CODE != 0x8);)So how can i improve this code?I can solve this problem from which part of the reference manual。
void Transmit_Message_1(uint32_t* buf)
{
CAN_0.MB[1].CS.B.CODE = 0x8; //MB TX inactive
CAN_0.MB[1].ID.B.ID_STD = 0; //set message STD ID
CAN_0.MB[1].DATA.W[0] = *buf; //data0 set
CAN_0.MB[1].DATA.W[1] = *(buf + 1); //data1 set
CAN_0.MB[1].CS.B.DLC = 8; //message length 8 bytes
CAN_0.MB[1].CS.B.RTR = 0; //remote frame disable
CAN_0.MB[1].CS.B.IDE = 0; //extended bit disable
CAN_0.MB[1].CS.B.SRR = 0; //not used with STD_ID
CAN_0.MB[1].CS.B.CODE = 0xC; //MB once transmit data
while (CAN_0.MB[1].CS.B.CODE != 0x8);
}
thank you very much !
Hello,
from my point of view, it is not necessary to wait until the message is sent from message buffer. Use for example FOR loop. In the FOR loop, fill MB0 and set code to 0xC, fill MB1 and set code to 0xC and so on.
To check, if MB was successfully transmitted, you can use for example interrupt. Another way is check message buffer status as soon as you will fill it again. The method you use is strictly dependent on your application requirements.
Regards,
Martin
thank you very much