cancel
Showing results for 
Search instead for 
Did you mean: 

I cube Lorawan Stack V1.3.1 user Code Not Working/Updating

MUsma.1
Associate II

Hi All ST Members

Hope you all are doing well! . I have a question , i will highly appreciate for the answer.

Currently i am using I cube Lorawan Stack V1.3.1 its compiling and working well with my Nucleo Board+ Sx1262 . But when i copy pasted the working code from another project in which HAL libraries used . In this project i interfaced the DS1307/TLV493D , read the data from it and displayed on UART perfectly .

After copy pasting all the code(DS1307/TLV493D) into the I cube Lorawan with all the variables with zero error . Program failed to work . I debugged the issue . Which i found is that

In working code of (DS1307/TLV493D) internal registers of I2C were updating in debug mode . I have attached the screen shot of it .

But after copy pasting program get stuck at this command

if(HAL_I2C_IsDeviceReady(&hi2c1 ,0x00 ,1,10)== HAL_OK){

HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5);

}

I debugged the issue , in which i found that internal registers of I2c are not updating at all . I also tried UART code / Timer Code which was working in separate project but doing same behavior as mentioned above for the case of I2C .Screen Shot is also attached which is showing internal registers are not updating.

Note *

I have also configured the I2C clock as well in system configuration function . I have also attached the main.c files for both the cases .

Thanks in Advance

Best Regards,

5 REPLIES 5

Check where you are enabling the clocks, perhaps in some MSP code. Enable the clock early enough for it to be usable at initialization, the MSP used an obfuscated/just-in-time approach.

Got an I2C OLED running of the LoRa-Disco board

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
MUsma.1
Associate II

Thanks for the reply !

I have called the functions in following sequence as for clocks are concerned can you please check it . At the end , i have pasted the  SystemClock_Config() .

Thanks In advance for the Help !

/////// Fn() Call Sequence //////////////////////

 HAL_Init();

 /* Configure the system clock*/

 SystemClock_Config();

 /* Configure the debug mode*/

 DBG_Init();

 /* Configure the hardware*/

 HW_Init();

 /* USER CODE BEGIN 1 */

MX_GPIO_Init();

 MX_I2C1_Init();

/////// Fn() Call Sequence //////////////////////

void SystemClock_Config(void)

{

  RCC_OscInitTypeDef RCC_OscInitStruct = {0};

 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

 /** Configure the main internal regulator output voltage 

 */

 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

 /** Initializes the CPU, AHB and APB busses clocks 

 */

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;

 RCC_OscInitStruct.HSIState = RCC_HSI_ON;

 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

 RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_6;

 RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_3;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  Error_Handler();

 }

 /** Initializes the CPU, AHB and APB busses clocks 

 */

 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV16;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)

 {

  Error_Handler();

 }

 PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2C1;

 PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1;

 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)

 {

  Error_Handler();

 }

}

__HAL_RCC_I2C1_CLK_ENABLE();

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
MUsma.1
Associate II

Thanks a lot for the help . Got the progress .....

i have called the function at , and also tried to call in  SystemClock_Config() startup but same response as mentioned in the snapshot .

Thanks for the help , now at least i2c is enabled but stuck at device ready () as mentioned in the screen shot .

__HAL_RCC_I2C1_CLK_ENABLE();

 hi2c1.Instance = I2C1;

 hi2c1.Init.Timing = 0x00303D5B;

 hi2c1.Init.OwnAddress1 = 0;

 hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;

 hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;

 hi2c1.Init.OwnAddress2 = 0;

 hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;

 hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;

 hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;

 if (HAL_I2C_Init(&hi2c1) != HAL_OK)

 {

  Error_Handler();

 }

MUsma.1
Associate II

Hi Clive1

thanks for the help ! i really appreciate it !

one thing i was missing while copying code from cubemx to i cube lora wan was pin configuration , which was present in HAL_I2C_MspInit();

i was only calling  // UNUSED(hi2c); only and not copying remaining code of I2C1 GPIO Configuration  

/////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////

 void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c)

{

 /* Prevent unused argument(s) compilation warning */

 // UNUSED(hi2c);

GPIO_InitTypeDef GPIO_InitStruct = {0};

 if(hi2c->Instance==I2C1)

 {

 /* USER CODE BEGIN I2C1_MspInit 0 */

 /* USER CODE END I2C1_MspInit 0 */

  

  __HAL_RCC_GPIOB_CLK_ENABLE();

  /**I2C1 GPIO Configuration  

  PB8  ------> I2C1_SCL

  PB9  ------> I2C1_SDA 

  */

  GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;

  GPIO_InitStruct.Pull = GPIO_PULLUP;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

  GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;

  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /* Peripheral clock enable */

  __HAL_RCC_I2C1_CLK_ENABLE();

 /* USER CODE BEGIN I2C1_MspInit 1 */

 /* USER CODE END I2C1_MspInit 1 */

 }

}

/////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////

Again Thank You !