2018-03-24 07:23 PM
Hello,
I'm currently writing a bare metal CAN driver for the STM32F302. I'm struggling to get transmission working at the moment. I've been reading through the HAL source as a double check and I can't seem to locate the detail I'm missing nor can I find the missing element in the reference manual chapter.
Here's where I'm at: I've configured the RCC for CAN and GPIOB (as well as all the GPIO settings), the bit timing and frequency (250 kbps if it matters), enable loopback in hardware, and set the peripheral to Normal mode (I've verified this by checking the INAK and SLAK bits in the MSR).
Then I initiate a transmission by first checking that mailbox 0 is empty, clearing the transmit request bit, loading my data into the mailbox, and then setting the transmit request bit. I check the ESR register for errors and I'm not getting any. On subsequent calls, I verify that the bit signifying that mailbox 0 is no longer empty is now cleared meaning there is data pending transmission.
However, data never sends. I'm monitoring the CANTX pin on a logic analyzer and the pin is pulled high, but never changes. I do not have a bus with a second node connected, but I do not know if this matters if the peripheral is in loopback mode. I've been struggling with this for quite some time, if anyone viewing this needs more information I'll gladly give it.
Thanks!
#problem #can #stm32f32018-03-25 04:55 AM
If you have a pending transmit frame, then the peripheral should either send that frame (raising TXOK) or enter into error mode (since there is no frame to preempt yours).
Make sure you don't use silent loopback mode, as it doesn't connect the internal CAN Tx line to the GPIO.
(And you will only receive a loopback frame if you configure a receive filter for it.)
2018-03-25 05:36 AM
Set ABOM to ENABLE
and
Use a pullup on the RXpin until you connect a linedriver chip.
I used a CanDo unit to transmit, and worked on the receiver first.
did you use the cube ?
2018-03-26 09:31 AM
I am enabling the ABOM bit, but there's currently no bus as I have the peripheral configured for Loopback mode. I'm using the stm32f3xx header, rather than Cube since I'm writing my own driver.
2018-03-26 10:34 AM
By default is the peripheral not setup to accept all messages and filter out none of the incoming messages? This had been my assumption as I haven't touched the filters yet and thought I could wait.
I've made sure to clear the SILM bit and start checking the TXOK bit. In the process, I noticed I was setting the MCR_RESET bit following changing the peripheral to INIT mode, which may have been causing issues like putting it back into sleep mode and preventing me from changing the BTR bits. I moved that bit set and I'm now getting output on the CANTX pin.
Thanks for your help!