How to ensure that an SPI master sends exactly 16 clock pulses to the slave?

by Xavier Pacheco Paulino   Last Updated October 18, 2018 23:25 PM

I'm using this current sensor: TLI4970-D050T4 According to the datasheet:

enter image description here

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_SPI_Receive(&hspi1, (uint8_t *)&SPIRx, 2, 10);

float motor_current() {

    float Iout;
    float BIout;
    int16_t Bit15;
     Bit15 = SPIRx&0x8000;
                HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_SET);
            else {
                BIout= SPIRx&0x1FFF;
                Iout = (BIout-4096)/80;
        return Iout;

Related Questions

Battery current measurement with shunt resistor

Updated April 04, 2017 17:25 PM