This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Read/Write Bit in SPI communications. How to.

I'm trying to connect with SPI interface. I've some little problems to understand about how technically do it,

I found this code on the web:

    uint8_t OUT_X_L_addr = 0x28; // The address of the register you want to write
uint8_t tx_data[2] = {0x00, 0x00}; // Transmit register
uint8_t rx_data[2] = {0x00, 0x00}; // Receive register

spi_master_init(SPI_MASTER_0, spi_master_0_event_handler, false);
// End SPI

// Enter main loop.
for (;;)
{
    tx_data[0] = (0x80 | OUT_X_L_addr); //Add the RW bit to the address.
    spi_master_send_recv(SPI_MASTER_0, tx_data, 2, rx_data, 2);
}

Just to understand how it works. Does this code write or read data to slave ?

As I understand this code:

tx_data[0] = (0x80 | OUT_X_L_addr); 

puts an 1 bit at the begigging of the Byte sent. That means it reads data from the address or it writes ?

Addresses could be only of length 7 bit  ?

What if I wanted to write data to the slave. What code should I use ?

Related