Search code examples
cspiesp32esp-idf

Why OR every SPI register of the SX1272 with 0x80


I use a library from GitHub that gives the functionality to read and write to the register of the SX1272 with SPI. It works great but i dont understand why the Lora_write_ref() function OR's every register with 0x80.

So when lets say I want to write to the Register FIFO (RegFifo) on address 0X00. I can't because the functions Or's the register with 0X80. I know that what I think is wrong because it works just fine but why?

Code from https://github.com/Inteform/esp32-lora-library

/**
* Write a value to a register.
* @param reg Register index.
* @param val Value to write.
*/
void 
lora_write_reg(int reg, int val)
{
  uint8_t out[2] = { 0x80 | reg, val };
  uint8_t in[2];

  spi_transaction_t t = {
    .flags = 0,
    .length = 8 * sizeof(out),
    .tx_buffer = out,
    .rx_buffer = in  
 };

 gpio_set_level(CONFIG_CS_GPIO, 0);
 spi_device_transmit(__spi, &t);
 gpio_set_level(CONFIG_CS_GPIO, 1);
}    

Solution

  • According to SX1272/73 datasheet it is part of the SPI interface for writing the registers:

    The first byte is the address byte. It is comprises:

    • A wnr bit, which is 1 for write access and 0 for read access.
    • Then 7 bits of address, MSB first.