cancel
Showing results for 
Search instead for 
Did you mean: 

What should I do when the process stops in the middle of a program?

baby_chicken
Associate

Hello everyone,

I am writing a program to read the gyro of the ICM42688P, but in the middle of the program, the process stops because it cannot be directed.

Here is the full text of the code↓

 

ICM42688P::ICM42688P(SPI_TypeDef *spi2, GPIO_TypeDef *cs_x, uint32_t cs_pin): spi2(spi2), cs_x(cs_x), cs_pin(cs_pin){}


void ICM42688P::setup(void){
	
    LL_SPI_Enable(spi2);

}

void ICM42688P::SPI_TransmitReceive(uint8_t *tx_data, uint8_t *rx_data, uint8_t length) {
    uint8_t count = length;

    //CS Low
    LL_GPIO_ResetOutputPin(cs_x,cs_pin);

    //data clear
    if (LL_SPI_IsActiveFlag_RXNE(spi2) == SET) LL_SPI_ReceiveData8(spi2);

    //SPI、enable
    if (LL_SPI_IsEnabled(spi2) == RESET) LL_SPI_Enable(spi2);

    //sending receiving
    while (count > 0) {
        LL_SPI_TransmitData8(spi2, *tx_data++);  //transmission
        while (LL_SPI_IsActiveFlag_TXE(spi2) == RESET);  //waiting transmission complete
        while (LL_SPI_IsActiveFlag_RXNE(spi2) == RESET);  //waiting reception complete
        *rx_data++ = LL_SPI_ReceiveData8(spi2);  //storage
        count--;
    }

    //CS High
    LL_GPIO_SetOutputPin(cs_x,cs_pin);
}

void ICM42688P::whoami() {
    uint8_t tx_data[2];
    uint8_t rx_data[2];

    //who_am_i  read
    tx_data[0] = (0x75 | 0x80);  //read
    tx_data[1] = 0x00;  //dummy

    SPI_TransmitReceive(tx_data, rx_data, 2);

    printf("who am i = %x\r\n", rx_data[1]);
}

 

 

The process stops in the following part↓

 

 

while (LL_SPI_IsActiveFlag_TXE(spi2) == RESET); 

while (LL_SPI_IsActiveFlag_RXNE(spi2) == RESET);

 

 

However, if this part is deleted, the process will not stop but will not return the value expected by whoami.

Is there any good solution?
Thank you in advance.

 

microcontroller stm32f407vgt6, cubeIDE

0 REPLIES 0