cancel
Showing results for 
Search instead for 
Did you mean: 

MLC functionality on MKSBOX1v1

bigcoronagigachad
Associate

I have this board with STM32L4R9 and I used CubeMX and Unico-GUI tools to generate a decision tree for MLC in .ucf format. I used a python script to convert this to C uint8_t array as follows:

 

const uint8_t lsm6dsox_ucf[] = {
0x10, 0x00,
0x11, 0x00,
0x01, 0x80,
0x05, 0x00,
0x17, 0x40,
0x02, 0x11,
...
};

In the generated main function I use my function to upload this array to MLC:
void lsm6dsox_load_ucf_via_spi()
{
size_t ucf_size = sizeof(lsm6dsox_ucf) / sizeof(lsm6dsox_ucf[0]);

for (size_t i = 0; i < ucf_size; i += 2)
{
uint8_t reg = lsm6dsox_ucf[i]; // Register address
uint8_t value = lsm6dsox_ucf[i + 1]; // Register value

lsm6dsox_spi_write(reg, value);
HAL_Delay(10);
}

HAL_Delay(10);
}
 
void lsm6dsox_spi_write(uint8_t reg, uint8_t value)
{
// The first byte is the register address (with MSB cleared for write).
uint8_t tx_data[2] = {reg & 0x7F, value};

// Pull CS low to select the sensor
HAL_GPIO_WritePin(CS_LSM6DSOX_GPIO_Port, CS_LSM6DSOX_Pin, GPIO_PIN_RESET);

// Send data over SPI
HAL_SPI_Transmit(&hspi1, tx_data, 2, HAL_MAX_DELAY);

// Pull CS high to deselect the sensor
HAL_GPIO_WritePin(CS_LSM6DSOX_GPIO_Port, CS_LSM6DSOX_Pin, GPIO_PIN_SET);

// Small delay for stability
HAL_Delay(10);
}
 
after which I constantly pool the 0x70 register for decision tree 1 output but it never changes
uint8_t lsm6dsox_spi_read(uint8_t reg)
{
uint8_t tx_data = reg | 0x80;
uint8_t rx_data = 0;

// Pull CS low to select the sensor
HAL_GPIO_WritePin(CS_LSM6DSOX_GPIO_Port, CS_LSM6DSOX_Pin, GPIO_PIN_RESET);

// Transmit the register address and receive the response
HAL_SPI_Transmit(&hspi1, &tx_data, 1, HAL_MAX_DELAY);
HAL_SPI_Receive(&hspi1, &rx_data, 1, HAL_MAX_DELAY);

// Pull CS high to deselect the sensor
HAL_GPIO_WritePin(CS_LSM6DSOX_GPIO_Port, CS_LSM6DSOX_Pin, GPIO_PIN_SET);

return rx_data;
}
 
When I manually upload the .ucf file using Unico-GUI the gesture detection works and I get changes in the status register on the UI. What am I doing wrong?
0 REPLIES 0