I am trying to use SPI on Xiao BLE sence run on Zephyr
#define SPI_OP_MODE SPI_OP_MODE_MASTER | SPI_TRANSFER_MSB | SPI_WORD_SET(8)
int write_e_paper(bool cmd_data, uint8_t content){
/* cmd_data: 1 => data, 0 => cmd */
int ret = 0;
struct spi_config config;
uint8_t tx_data[1] = {content};
struct spi_buf_set tx_set ;
config.frequency = 1000000U;
config.operation = SPI_OP_MODE;
config.slave = 0;
config.cs = cs_ctrl;
const struct spi_buf tx_buf[1] = {
{
.buf = tx_data,
.len = ARRAY_SIZE(tx_data)
}
};
tx_set.buffers = tx_buf;
tx_set.count = 1 ;
gpio_pin_set_dt(&dc_select_pin, cmd_data);
// k_sleep(K_MSEC(20));
/* For loop back test */
#if 1
uint8_t rx_data[1];
struct spi_buf rx_buf[1] = {
{.buf = rx_data, .len = 1},
};
struct spi_buf_set rx_set = { .buffers = rx_buf, .count = 1 };
ret = spi_transceive(spi_dev, &config, &tx_set, &rx_set);
printf(" tx_set.count : %d, tx_set->buf->len : %d, tx_set->buf->buf : %02x, tx (i) : %02x\n",
tx_set.count, tx_set.buffers[0].len, *((uint8_t *)tx_set.buffers[0].buf), content);
if (ret){
printf("%s fail: content : 0x%x, ret: %d\n", __func__, content, ret);
}
#endif
return ret;
};
int main(void)
{
while(1){
write_e_paper(0, 0xFF);
write_e_paper(0, 0x11);
}
}
The console output is
tx_set.count : 1, tx_set->buf->len : 1, tx_set->buf->buf : ff, tx (i) : ff
tx_set.count : 1, tx_set->buf->len : 1, tx_set->buf->buf : 11, tx (i) : 11
But when I check logic analyzer I got 0xEE 0x00
Also My e-paper can not work.
I check my e-paper and logic analyzer on Arduino, both of them work very well.