I'm using this current sensor: TLI4970-D050T4 According to the datasheet:
How can the SPI master send exactly 16 clock pulses to the slave, so I don't receive the 0's?
When I'm reading this sensor, I get a lot of 0's. So, I thought that it might be the reason, that I'm sending more than 16 clocks pulses. I'm using an STM32 Nucleo running at 2 MHz, but the SPI clock has been prescaled to 1 MHz. I would appreciate any advice. This is the code that I use to read the sensor and calculate current:
while (1)
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
HAL_SPI_Receive(&hspi1, (uint8_t *)&SPIRx, 2, 10);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
motorCurrent=motor_current();
float motor_current() {
float Iout;
float BIout;
int16_t Bit15;
Bit15 = SPIRx&0x8000;
if(Bit15==0x8000){
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_SET);
}
else {
BIout= SPIRx&0x1FFF;
Iout = (BIout-4096)/80;
}
return Iout;
}