Skip to main content
Explorer
July 11, 2024
Solved

While Syntax Error in STM32F105 using KEIL compiler

  • July 11, 2024
  • 2 replies
  • 908 views

we have assigned a while condition below the given code, even if the condition is false, or the while condition gets 0, the code also does not execute, it stucked at program counter on while only, if I entered a delay of 1 ms, using Hal_delay after While, then only while condition gets execute, I don't know why after hal delay after while condition it working ok, 

int I2C_ReadRegForCC3Current(uint8_t reg_addr, uint8_t *reg_data, uint8_t count)
{
//unsigned int RX_CRC_FailForCC3Current = 0; // reset to 0. If in CRC Mode and CRC fails, this will be incremented.
// uint8_t RX_BufferForCC3Current [MAX_BUFFER_SIZEForCC3Current] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};//,0x00,0x00};
RX_CRC_FailForCC3Current = 0; // reset to 0. If in CRC Mode and CRC fails, this will be incremented.

#if CRC_Mode
{
crc_countForCC3Current = count * 2;
unsigned int jForCC3Current;
unsigned int iForCC3Current;
//unsigned char CRCcForCC3Current = 0;
CRCcForCC3Current = 0;
tempCRCcForCC3Current=0;
RX_CRC_FailCounter=0;
Flags.BQDataReceiveComplete=0;
//readstatus=HAL_I2C_Mem_Read(&hi2c2, DEV_ADDR, reg_addr, 1, ReceiveBufferForCC3Current, crc_countForCC3Current, 5000);
HAL_I2C_Mem_Read_DMA(&hi2c2, DEV_ADDR, reg_addr, 1, ReceiveBufferForCC3Current, crc_countForCC3Current);
//HAL_Delay(20);

Flags.BQDataReceiveComplete = 1; // this flag is 1 ,we checked in debugging
while(!Flags.BQDataReceiveComplete) // here I have a delay below to execute to next step,

HAL_Delay(0); // need to enter delay forcefully to execute to next step.


uint8_t crc1stByteBufferForCC3Current [4] = {0x10, reg_addr, 0x11, ReceiveBufferForCC3Current[0]};
    This topic has been closed for replies.
    Best answer by Tesla DeLorean

    So what's the syntax error say?

    You need semicolon or compound statement after the while()

    You'll also want the variable to be volatile if changed in an interrupt or callback context.

    2 replies

    Graduate II
    July 11, 2024

    So what's the syntax error say?

    You need semicolon or compound statement after the while()

    You'll also want the variable to be volatile if changed in an interrupt or callback context.

    Explorer
    July 17, 2024

    Thank you so much, by taking a volatile variable, problem has been ressolved.