cancel
Showing results for 
Search instead for 
Did you mean: 

Send CAN bus message with STM32F469I-DISCO

Maskart
Associate II

Hello!

I've searched but can't find a solution for my problem.

I'm developing a project with TouchGfx and Cube IDE that I'll be using to send CAN bus messages to wakeup automotive components like ecu's and dashboards. I've made all the GUI and also tested the buttons by activating the onboard led's. I've made the connection to CAN1 (that is connected to micro USB port and i've already tested and it's working fine (making a simple project without touchgfx) but I'm lost on how to send my messages from the GUI by pressing a button. I've seen some examples that put the code on the files like Screen1View.cpp and I've tested the led's example sucessfuly doing that but no CAN bus.

Configured CAN1 for 500kbit's, RX pullup, and all atached to MCP2515 transceiver.

I've tried also other similar methods like UART send but can't get CAN working.

Can you point me to some tutorials or tell me the best way to do it?

Thank you for your help!!!

Rick

 

9 REPLIES 9
Issamos
Lead II

Hello @Maskart 

I suggest you to create buttons using touchgfx for every operation and so when you activate an event by clicking on this button you can use the callback of this event to send the message you already programmed using CAN interface. Also, you can use the same exemple using LEDs but this time you can change the LED ON by sending a message using CAN.

Best regards.

II

Maskart
Associate II

Thank you @Issamos !

I've already tried that but something must be wrong.

The code I'm using is pasted bellow. I have the button that activates the led and also the button that shoul send the CAN message. Debuging the code I can see that the message is loaded to TxMailbox but I can't get it with my CAN Sniffer (I'm using Peak's P-CAN).

 

CODE:

}

void psaView::psa_exe()

{

 

CAN_HandleTypeDef hcan1;

HAL_CAN_Start(&hcan1);

CAN_TxHeaderTypeDef TxHeader;

uint8_t TxData[8];

 

while (1)

{

// Message 276

TxHeader.StdId = 0x276;

TxHeader.ExtId = 0;

TxHeader.RTR = CAN_RTR_DATA;

TxHeader.IDE = CAN_ID_STD;

TxHeader.DLC = 8;

TxData[0] = 0x87;

TxData[1] = 0x11;

TxData[2] = 0x0A;

TxData[3] = 0x13;

TxData[4] = 0x2B;

TxData[5] = 0x0B;

TxData[6] = 0xB8;

TxData[7] = 0xB9;

if (HAL_CAN_AddTxMessage(&hcan1, &TxHeader, TxData, NULL) != HAL_OK)

{

Error_Handler();

}

HAL_Delay(1000);

 

}

}

 

void psaView::psa_exe_2()

{

HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_4); /*LED on board ON OFF*/

 

}

 

Thank you!!

 

Issamos
Lead II

The best solution is going to be by combining the 2 testes you have done ( the led test and the CAN test). Use the first one to get acknowledge about the bouton activation and the second to send the data. And the most important is to verify the compatibility of your configurations with the needs of the code.

Best regards.

II

Maskart
Associate II

I've tested what you said and I have the led on and off every second but no CAN message. The strange thing is that the message is loaded to Tx Mailbox but I have no transmission. I have a BP at:

 if (HAL_CAN_AddTxMessage(&hcan1, &TxHeader, TxData, NULL) != HAL_OK)

and the result is on the image atached.

Thanks

Have a enabled the transmission.

Best regards.

II

Hi!

What do you mean about enable the transmission? I've tried so many things and I can't find the problem...

The LED code executes but CAN is never transmited. Can it be a problem with Can Mailboxes?

Thanks

Karl Yamashita
Lead II

@Maskart The MCP2515 is a CAN Controller, not a CAN Transceiver. Unless you meant to say MCP2551?

If you are indeed using the MCP2515, then you can't use the CAN peripheral of the STM32F469I-DISCO because it doesn't use the SPI bus

If you find my answers useful, click the accept button so that way others can see the solution.
Maskart
Associate II

@Karl Yamashita thank you for your answer!! It was my mistake, sorry - I'm using MCP2551. If I compile a simple project with CAN 1 and 2 active I can see the messages being sent with my Peak PCanUSB on both CAN1 and CAN2 and I can change the CAN bitrate. I think the problem is that my program never get one available mailbox but I can't figure it out. Can someone tell me how do I check my mailboxes when debuging my code? I've put some breakpoints and I can see that my messages are loaded but I think they are waitng for available mailboxes.

Thank you for your great help!!!!

Rick

Maskart
Associate II

I found that if I insert breakpoint at 

 

MX_CAN1_Init();

pressing F5 the code jumps to this line

 

hcan1.Init.TransmitFifoPriority = DISABLE;

and does not load the CAN initialization values like prescaler and parameters. 

When it arrives to 

 

if(HAL_CAN_AddTxMessage(&hcan2, &TxHeader, TxData, NULL) != HAL_OK)

stepping through debug with F5 I get CAN NOT INITIALIZED.

Why it's jumping the CAN parameters loading?

I've made a new project just with CAN and GPIO for led and if I step the code with F5 I get all the parameters loaded.

What can be the problem?

Thanks for all the help!!!!

Rick