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_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;
     }


Related Questions






Battery current measurement with shunt resistor

Updated April 04, 2017 17:25 PM