Problem connecting SPI to
I am new to STM32. I am porting my code from ATMega128 to STM32 for faster thru put . I have to connect W5500 to STM32F103 on SPI2.
To test my understanding of SPI on STM32 after compiling , a small test code in while loop.
SPI_Write(S0_CR,CR_CLOSE); //#define S0_CR 0x0001, CR_CLOSE 0x10;
data_read = SPI_Read(S0_CR);
used the below sub functions
void SPI_Write(int addr,char data)
{
SPI_select
HAL_SPI_Transmit(&hspi2, ((addr & 0xFF00) >> 8), 1, 100);
HAL_SPI_Transmit(&hspi2, (addr & 0x00FF),1,100);
HAL_SPI_Transmit(&hspi2, (WRITE_OPCODE_S0),1,100);
HAL_SPI_Transmit(&hspi2, data, 1, 100);
SPI_deselect
}
char SPI_Read(int addr)
{
SPI_select
HAL_SPI_Transmit(&hspi2,((addr & 0xFF00) >> 8),1,100);
HAL_SPI_Transmit(&hspi2,(addr & 0x00FF),1,100);
HAL_SPI_Transmit(&hspi2,(READ_OPCODE_S0),1,100);
HAL_SPI_Receive(&hspi2,spi_rec,1,100);
SPI_deselect
return spi_rec;
}
Expected 0x10 (16) in data_read but got zero. thru UART. Tried diagnosing with
if(Err !=HAL_OK)
SPI_Write works to HAL_OK when first line address is not 0x00;
DSO Shows no SCK pulses when it is 0x00 though CS goes low.
Similarly in SPI_Read; line -- HAL_SPI_Receive(&hspi2,spi_rec,1,100); gives !=HAL_OK on UART
My proceeding further depends on clearing these doubts. Request help please.
