I have the following SPI code for STM32 but is not working. I am using SPI3 with PB3, PB4, PB5 and PE1 for chip select.
When i debug the SPI3_Write(0x06); line the code gets stuck in a read loop. This section of assembly is run forever.
Code: Select all
L___Lib_SPI_123_SPIx_Read0:
; base start address is: 0 (R0)
0x0740 0xF2000208 ADDW R2, R0, #8
0x0744 0x6813 LDR R3, [R2, #0]
0x0746 0xF3C30200 UBFX R2, R3, #0, #1
0x074A 0xB902 CBNZ R2, L___Lib_SPI_123_SPIx_Read1
;__Lib_SPI_123.c, 70 ::
0x074C 0xE7F8 B L___Lib_SPI_123_SPIx_Read0
L___Lib_SPI_123_SPIx_Read1:
Any idea why this is happening? This is my code:
Code: Select all
unsigned int take, buffer;
void main() {
// Initialize the SPI1 module with default settings
SPI3_Init();
// PE1 on MCU is connected to CS on adc. Set high initially
GPIO_Digital_Output(&GPIOE_ODR, _GPIO_PINMASK_1); // Set PORTE Pin1 as output
GPIOE_ODR = 1 ; // Set PORTE high
Delay_ms(1000);
while(1) {
// Select the device by seting chip select low
GPIOE_ODR = 0 ;
SPI1_Write(0x06);
// read a word from the SPI bus
take = SPI_Read(buffer);
// Deselect the device
GPIOE_ODR = 1 ;
// delay some time before reading again
Delay_ms(1000);
}
}