iC-Haus MCW via ESP32 SPI

watersnick@gmail.com
Posts: 1
Joined: Thu Oct 03, 2024 5:13 pm

iC-Haus MCW via ESP32 SPI

Postby watersnick@gmail.com » Thu Oct 03, 2024 5:57 pm

I am trying to collect the status information from an embedded chip: iC-Haus MCW via SPI. The SPI Host is via the ESP32 Thing.

The SPI transaction should send 1 byte as an op code and receive one byte containing the status.

The first byte of MOSI is the command’s opcode
0x9C and the second byte of MISO shows the latched
status information.

iC-MCW Specs:
CPOL = 0, CPHA = 0
CPOL = 1, CPHA = 1
SPI Min Clock 10Mhz
status.png
status.png (17.99 KiB) Viewed 89 times
This seems straight forward enough but I am not getting a response. The output repeats in a loop and is always 0. Am I missing something? I suspect the CS line may be the culprit, its held high by the MCW dev board when unplugged at 5V. It high 3.6 when connected to pin 5.

Code: Select all

Tx Byte 0: 0x9C
Tx Byte 1: 0x0
Rx Byte 0: 0x0
Rx Byte 1: 0x0
  1. #   define PIN_NUM_MISO     19
  2. #   define PIN_NUM_MOSI     23
  3. #   define PIN_NUM_CLK      18
  4. #   define PIN_NUM_CS       5
  5.  
  6. void mcw_get_status(spi_device_handle_t spi){
  7.     esp_err_t ret;
  8.  
  9.     spi_transaction_t t;
  10.    
  11.     uint8_t cmd_buff[2];
  12.     cmd_buff[0] = 0x9C;
  13.     cmd_buff[1] = 0x00;
  14.  
  15.     for (int i = 0; i < 2; i++){
  16.         printf("Tx Byte %d: 0x%X\n", i, cmd_buff[i]);
  17.     }
  18.  
  19.     memset(&t, 0, sizeof(t));
  20.  
  21.     t.length  = 8 * 2;
  22.     t.tx_buffer = &cmd_buff;
  23.     t.flags = SPI_TRANS_USE_RXDATA;
  24.  
  25.     ret = spi_device_polling_transmit(spi, &t);
  26.     assert(ret == ESP_OK);
  27.  
  28.     for (int i = 0; i < t.rxlength / 8; i++){
  29.         printf("Rx Byte %d: 0x%X\n", i, t.rx_data[i]);
  30.     }
  31. };
  32.  
  33. void mcw_init(spi_device_handle_t spi){
  34.     mcw_get_status(spi);
  35. };
  36.  
  37. void app_main(void)
  38. {
  39.     spi_device_handle_t spi;
  40.  
  41.     spi_bus_config_t buscfg = {
  42.         .miso_io_num = PIN_NUM_MISO,
  43.         .mosi_io_num = PIN_NUM_MOSI,
  44.         .sclk_io_num = PIN_NUM_CLK,
  45.         .quadwp_io_num = -1,
  46.         .quadhd_io_num = -1,
  47.         .max_transfer_sz = 2,
  48.     };
  49.    
  50.     spi_device_interface_config_t devcfg = {
  51.         .clock_speed_hz = 10 * 1000 * 1000,
  52.         .mode = 0,
  53.         .spics_io_num = PIN_NUM_CS,
  54.         .queue_size = 10,
  55.     };
  56.  
  57.     esp_err_t ret = spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO);
  58.     ESP_ERROR_CHECK(ret);
  59.  
  60.     ret = spi_bus_add_device(SPI2_HOST, &devcfg, &spi);
  61.     ESP_ERROR_CHECK(ret);
  62.  
  63.     while(true) {
  64.         mcw_init(spi);
  65.         sleep(2);
  66.     }
  67. }

Who is online

Users browsing this forum: No registered users and 103 guests