Good afternoon everyone, i am looking for a little help on what must be a pretty basic issue.
I am running the CAN PAL sample project and can send a receive messages but when i try to modify the main.c to package the data from an array using a for loop, it flashes to the device successfully but when i hit debug, i get the below in the console and the debug stops automatically.
UsageFault:An Unaligned access error has occurred
HardFault: A fault has been escalated to a hard fault
All i have added is a manual method for packaging data bytes into the transmit buffer but im having to do it in 8 separate commands, ive added a simple for loop but that kills the program. Im very used to using the Arduino IDE and this is my attempt to move forward with a more professional platform so any help would be great
Thanks
Rich
(*(uint32_t *)&CAN_TX_Buffer.id = 0x600);// sets the CAN ID to transmit
unsigned char data2[8] = {7, 6, 5, 4, 3, 2, 1, 0};// Sets the data to send into a character array
for(int t=0; t<7; t++){
(*(uint64_t *)&CAN_TX_Buffer.data[t] = data2[t]);/* increase the data, [2] is the byte of data in the 8 byte message to update */
//(*(uint64_t *)&CAN_TX_Buffer.data[0] = data2[0]);/* increase the data, [2] is the byte of data in the 8 byte message to update */
//(*(uint64_t *)&CAN_TX_Buffer.data[1] = data2[1]);/* increase the data, [2] is the byte of data in the 8 byte message to update */
//(*(uint64_t *)&CAN_TX_Buffer.data[2] = data2[2]);/* increase the data, [2] is the byte of data in the 8 byte message to update */
//(*(uint64_t *)&CAN_TX_Buffer.data[3] = data2[3]);/* increase the data, [2] is the byte of data in the 8 byte message to update */
//(*(uint64_t *)&CAN_TX_Buffer.data[4] = data2[4]);/* increase the data, [2] is the byte of data in the 8 byte message to update */
//(*(uint64_t *)&CAN_TX_Buffer.data[5] = data2[5]);/* increase the data, [2] is the byte of data in the 8 byte message to update */
//(*(uint64_t *)&CAN_TX_Buffer.data[6] = data2[6]);/* increase the data, [2] is the byte of data in the 8 byte message to update */
//(*(uint64_t *)&CAN_TX_Buffer.data[7] = data2[7]);/* increase the data, [2] is the byte of data in the 8 byte message to update */
}
CAN_Send(&can_pal1_instance, TX_MB, &CAN_TX_Buffer);// Sends the CAN message using non blocking type
Hi Petr, this fixed my issue, thank you very much.
Regards
Rich
Hi Petr,
I have simplified my code for the CAN message send now but i am struggling to achieve a similar function with receiving CAN messages, i effectively want to receive in all messages and then check the ID and assign the data to a character array depending on the ID.
I have tried a couple of options and looked through the different CAN examples but im not able to access the CAN ID variable. I am not using flex CAN just standard CAN 11 bit ID's .
I need to set up a CAN receive instance, set up the message buffer and then do something different based on the IS of the message that comes through.
a bit like
CAN_RECEIVE (SETUP) What is this command???
CAN_RECEIVE (MESSAGE) What is this command??
if (CAN_RECEIVE.ID == 0x800){ what is this command??
for (j=0;j,7;j++){
char message1[j] = CAN_RECEIVE.data[j] What is this command???
}
else if (CAN_RECEIVE.ID == 0x700){
for (j=0;j,7;j++){
char message2[j] = CAN_RECEIVE.data[j]
}
Are you able to point me in the right direction please?
Thanks
Rich
Hi,
refer to SDK demo code, it shows how to config and use MB for receiving.
If you want to receive all IDs into single MB then clear respective mask acceptance register.
below is possible code, but using FlexCAN driver
HI Petr,
Could you advise which SDK CAN example i should use with the code you have provided please?
Thanks
Rich