SPI transmit and receive.
Hi All.!!!
I am working on STM32F103 and using its 4-wire SPI for communication with slave whose data is 32bit and addr is 16bit.
What I am trying to do is to write and read slave but i could not below is the settings that
I have done in STM cube MX.
Mode:- Full Duplex Master
Data Size 16 bit
Pre scaler 32 selected.
For write operation
uint8 WriteBronco(uint32 Data,uint16 Addr)
{
uint32_t data[2];
data[0] = Addr; // multibyte write enabled
data[1] = Data; //32bit of data slave
HAL_GPIO_WritePin (GPIOB, GPIO_PIN_6, GPIO_PIN_RESET); // pull the cs pin low to enable the slave
HAL_SPI_Transmit (&hspi1, data, 2, 100); // transmit the address and data
HAL_GPIO_WritePin (GPIOB, GPIO_PIN_6, GPIO_PIN_SET); // pull the cs pin high to disable the slave
return 0;
}
For Read operation
void adxl_read (uint16_t address)
{
address = 0x8000; //
address = 0x4000; //
HAL_GPIO_WritePin (GPIOB, GPIO_PIN_6, GPIO_PIN_RESET); // pull the cs pin low to enable the slave
HAL_SPI_Transmit (&hspi1, &address, 2, 100); // send the address from where you want to read data
HAL_SPI_Receive (&hspi1, data_rec, 6, 100); // read 6 BYTES of data
HAL_GPIO_WritePin (GPIOB, GPIO_PIN_6, GPIO_PIN_SET); // pull the cs pin high to disable the slave
}
Kindly let me know how I can do this ??