My write function is the following:
Code: Select all
void max_write8(uint8_t address, uint8_t data, uint8_t sensor_ch){
spi_transaction_t trans_desc;
uint8_t tx_data[2];
trans_desc.addr=0;
trans_desc.cmd=0;
trans_desc.flags = 0;
trans_desc.length = 8;
trans_desc.rxlength = 0;
trans_desc.tx_buffer = tx_data;
//memset( &trans_desc, 0, sizeof( spi_transaction_t ) );
tx_data[0] = (address | 0x80);
ESP_ERROR_CHECK(spi_device_transmit(handle, &trans_desc));
tx_data[0] = data;
ESP_ERROR_CHECK(spi_device_transmit(handle, &trans_desc));
}
Code: Select all
void init(){
bus_config.sclk_io_num = 18; // CLK
bus_config.mosi_io_num = 23; // MOSI
bus_config.miso_io_num = 19; // MISO
bus_config.quadwp_io_num = -1; // Not used
bus_config.quadhd_io_num = -1; // Not used
ESP_ERROR_CHECK(spi_bus_initialize(HSPI_HOST, &bus_config, 0));
spi_device_interface_config_t dev_config;
dev_config.address_bits = 0;
dev_config.command_bits = 0;
dev_config.dummy_bits = 0;
dev_config.mode = 0;
dev_config.duty_cycle_pos = 0;
dev_config.cs_ena_posttrans = 0;
dev_config.cs_ena_pretrans = 0;
dev_config.clock_speed_hz = 1000000;
dev_config.spics_io_num = 5;
dev_config.flags = 0;
dev_config.queue_size = 1;
dev_config.pre_cb = NULL;
dev_config.post_cb = NULL;
ESP_ERROR_CHECK(spi_bus_add_device(HSPI_HOST, &dev_config, &handle));
max_write8(0x02, 0x00,0);
max_write8(0x00, 0x10,0);
}