cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F427 CAN1 crashes SPI2

john239955_st
Associate III
Posted on September 13, 2016 at 13:41

STM32Cube FW_F4 V1.13.0

I have a board using CAN1, CAN2, SPI_1 and SPI_2

All functions work independantly fine CAN1 and CAN2 work in Polling mode and Interrupt mode.

SPI_1 and SPI_2 work OK in polling mode using as follows:-

HAL_SPI_TransmitReceive(&hspi1, SPI_Data_Wr_ADC1, SPI_Data_Rd_ADC1, 27, 100); // for SPI2 use (&hspi2)

CAN1 and CAN2 work OK using as follows:-   // (hcan2) for CAN2

           hcan1.pTxMsg->StdId = Out_ID;

           hcan1.pTxMsg->DLC = 8;

           hcan1.pTxMsg->RTR = CAN_RTR_DATA;

           hcan1.pTxMsg->IDE = CAN_ID_STD;

    

           hcan1.pTxMsg->Data[0] = byte1;                                         

           hcan1.pTxMsg->Data[1] = byte2;                             

           hcan1.pTxMsg->Data[2] = byte3;                             

           hcan1.pTxMsg->Data[3] = byte4;

           hcan1.pTxMsg->Data[4] = byte5;                            

           hcan1.pTxMsg->Data[5] = byte6;                                        

           hcan1.pTxMsg->Data[6] = byte7;                        

           hcan1.pTxMsg->Data[7] = byte8;

           if(HAL_CAN_Transmit_IT(&hcan1) != HAL_OK)

                        {

                            

                            Error_Handler(); // Send my Error

                            

                        }

The code works fine until CAN1 transmits an ID greater that 0x03 in StdID which stops SPI_2 from working, SPI_1 continues to work OK, this fault occurs only in CAN1 if CAN2 Transmit is used all works fine.

I have not used any debug as not sure if fault is generated by CAN1 and it's effect on SPI_2

Any help would be appreciated. KR John W

1 REPLY 1
john239955_st
Associate III
Posted on September 14, 2016 at 15:36

Hi All,

Re:- Corruption of  SPI2.

I have found my error, my ADC can be configured for 16 or 24 bit.

HAL_SPI_TransmitReceive(&hspi1, SPI_Data_Wr_ADC1, SPI_Data_Rd_ADC1, 27, 100);

In early days I configured  SPI_Data_Wr_ADC1 with 19 byte array, I subsequently went to 24 bit with a 27 byte array and had not extended the array to 27 bytes, with subsequent consequences. It would appear that

hcan1.pTxMsg->StdId = Out_ID;  wrote data into the end of SPI_Data_Wr_ADC1 array disrupting the ADC.

KR John W