2018-09-21 07:39 AM
I have two STM32F303CB connected over the CAN bus. Not directly, with SN65HVD231D.
The first one is a master the second one is a slave. Master-slave I mean on application level.
Receiving a message is the same
void USB_LP_CAN1_RX0_IRQHandler(void)
{
can_params.message_received = 1;
can_params.fifo_num = CAN_FIFO0;
CAN_Receive(CANx, CAN_FIFO0, &RxMessage);
}
Sending a message is the same too
uint8_t CAN_TX(uint8_t mot_id, uint8_t opcode, uint8_t *data, uint32_t data_size)
{
uint8_t mailbox_num;
TxMessage.RTR = CAN_RTR_DATA;
TxMessage.IDE = CAN_ID_EXT;
TxMessage.ExtId = (opcode << 8) | mot_id;
if (data_size > 8)
data_size = 8;
TxMessage.DLC = data_size;
memcpy(&TxMessage.Data[0], data, data_size);
mailbox_num = CAN_Transmit(CANx, &TxMessage);
return mailbox_num;
}
Master sends
void main (void)
{
while(1)
{
// do some stuff
CAN_TX(100, MASTER_COM_WHO_IS, can_data_buf, 0);
}
}
I get the message on the slave side
void CAN_TX_Slave(uint32_t opcode)
{
switch (opcode)
{
//got here
case CAN_COM_WHO_IS :
size = 0;
//sends an answer
CAN_TX(motor_sys_params.mot_id, CAN_COM_I_AM, data, 0);
break;
}
}
But the master didn't get it in void USB_LP_CAN1_RX0_IRQHandler(void).
If I pause - the master gets it. Should I free the line to get an answer?
At some point on the slave side REC = 0xFF and TEC = 0xF8 and it freezes.
How should I set a proper communication between two chips?
2018-09-22 01:20 AM
my only thought is that if you are pounding the transmit buffer... like here :
CAN_TX(100, MASTER_COM_WHO_IS, can_data_buf, 0);
is there time for a lower priority response ?
do you have a scope ?
can you see 1 message and then a quiet Bus is a happy bus....
ABOM has to be ENABLED
Do you have a CanBus Dongle ?
I used the CanDo unit, transmitted every second until I got the receiver running.
easy from there...
2018-10-20 10:45 PM
Thank you. Seems like ABOM = ENABLED did it.