Code: Select all
spi.write(bytearray([PAGE_FLAG | page]))
spi.write(bytearray([address]))
return spi.read(3, write=0xff)
Code: Select all
spi_transaction_t page_transaction = {
.tx_data={PAGE_FLAG | page},
.length=1 * 8,
.flags = SPI_TRANS_USE_TXDATA,
};
spi_transaction_t address_transaction = {
.tx_data={address},
.length=1 * 8,
.flags = SPI_TRANS_USE_TXDATA,
};
spi_transaction_t read_transaction = {
.tx_data={0xff, 0xff, 0xff},
.length=3 * 8,
.rx_buffer=rx_buffer,
.rxlength=3 * 8,
.flags = SPI_TRANS_USE_TXDATA,
};
pin_low(CS_METER34);
ESP_ERROR_CHECK(spi_device_transmit(powermeter_device_handle, &page_transaction));
ESP_ERROR_CHECK(spi_device_transmit(powermeter_device_handle, &address_transaction));
ESP_ERROR_CHECK(spi_device_transmit(powermeter_device_handle, &read_transaction));
pin_high(CS_METER34);
Below I try and read an address 4 times, the address should be 82 8F 5C:
Code: Select all
82 02 00
5c 00 02
82 02 00
5c 00 02
I can communicate with another, different spi device on the same bus so I think my IDF C code is at least vaguely sensible but I am more a python programmer than a C programmer.
I have tried various other things which didn't work:
- Doing page, address and read all in one transaction
- Reading 3 seperate bytes back, with and without 0xff
- Putting various delays in
- Using .cmd and .addr parts of transaction
Unfortunately I can't find the micropython source for machine.SPI.read(), I don't know why.