1
\$\begingroup\$

I'm trying to read registers from current-sensing chip ACS71020 connected over SPI.

This is how I initialize the SPI:

bc_spi_init(BC_SPI_SPEED_1_MHZ, BC_SPI_MODE_0);

The code for reading is such:

    uint8_t tx_buffer[2]= {0x1E | 0x80 };  // Register to read with highest bit set to 1 
    uint8_t rx_buffer[4] = {0x01, 0x02,0x03, 0x04};        

    if(bc_spi_is_ready())
    { 
        bc_spi_transfer(tx_buffer, NULL, 0);
        bc_spi_transfer(NULL, rx_buffer, sizeof(rx_buffer));
        bc_log_info("rx_buffer1:%d", rx_buffer[0]);  
        bc_log_info("rx_buffer2:%d", rx_buffer[1]);  
        bc_log_info("rx_buffer3:%d", rx_buffer[2]);  
        bc_log_info("rx_buffer4:%d", rx_buffer[3]);  
    } 

` Is it correct to set the highest bit of the register to 1 when reading? That is how I understand the spec.

Also no matter what register I read, I always get the same four values back. Is there something I'm missing?

I'm using the Big Clown (STM32L083CZ) https://developers.hardwario.com/hardware/about-core-module

\$\endgroup\$
3
  • \$\begingroup\$ Which MCU are you using? \$\endgroup\$ Commented Apr 20, 2020 at 20:10
  • \$\begingroup\$ I'm using the Big Clown (STM32L083CZ) developers.hardwario.com/hardware/about-core-module \$\endgroup\$ Commented Apr 21, 2020 at 10:27
  • \$\begingroup\$ That's what I suspected. I believe that STM32 SPI uses MSB first shift order by default, and the Big Clown API doesn't appear to have an option for changing it. \$\endgroup\$ Commented Apr 21, 2020 at 20:06

1 Answer 1

1
\$\begingroup\$

The ACS71020 expects SPI data MSB first, with the slave address bits 6:0 sent first followed by the read/write bit. Therefore the value should be {(0x1e << 1) | 0x01}

If your SPI port has configurable bit shift order then it should also be set for MSB first (this may be the default).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.