cancel
Showing results for 
Search instead for 
Did you mean: 

P-NUCLEO-IOD01A1 IO-Link (USART1) and USART2

JoaquimMartinez
Associate

Hi,

I am developing a IO-Link device and I am using the P-NUCLEO-IOD01A kit demo. The IO-Link works fine. Now I need to use a serial communication to receive a frame from another device. For this I use USART2. I use the example "UART_HyperTerminal_TxPolling_RxIT" and I've implemented the code in the P_NUCLEO_IOD01A1_Demo_Lib project (Io-Link project/example). IO-Link communication uses USART1.

The USART2 example just configures the uart and the System Clock. The clock setup is done by the function "SystemClock_Config();", please below. This function overwrite the RCC register values configured by the IO-Link function "stack_init();". In fact, they overwrites each other depending on the order I put both functions in my code. If I initialize first the "stack_init();" and then the "SystemClock_Config();", UART2 works fine but IO-Link doesn't and vice versa. 

I don't have access to the internal functions of "stack_init();" due is a limited example.

I think USART1 uses the PLL and USART2 uses the MSI clock.

I've tried to use the same clock for UART2 than IO-Link USART1, but it doesn't work. The baud rate for USART2 is updated according to the clock setup, but there is something more that I can't see because I am not very familiarized with STM32 MCU. 

The problem is when is called the function "HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0)!" in the "SystemClock_Config();". I think there is some registers that are not configured correctly due to the overwrite, but after several configuration I can't fix the problem.

Please, refer to the three files of internal MCU registers and to the RCC comparison tables:

  1. CPU_REG_YES_IO-Link_Config_YES_UART2_Configuration_and_NO_SystemClockConfig.txt
    1. Here the IO-Link works fine.
    2. UART2 doesn't work. I can't receive the UID from the reader.
  2. CPU_REG_NO_IO-Link_Config_YES_UART2_Configuration_and_YES_SystemClockConfig.txt
    1. Here the UART2 works fine and I can receive the UID from the reader.
    2. IO-Link doesn't work.
  3. CPU_REG_YES_IO-Link_Config_YES_UART2_Configuration_and_YES_SystemClockConfig.txt
    1. Here the UART2 works fine and I can receive the UID from the reader.
    2. IO-Link doesn't work.

Please, can anybody help me with this?

Thanks.

Joaquim.

 

void SystemClock_Config(void)

{

RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

RCC_OscInitTypeDef RCC_OscInitStruct = {0};

 

// Enable MSI Oscillator

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;

RCC_OscInitStruct.MSIState = RCC_MSI_ON;

RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_5;

RCC_OscInitStruct.MSICalibrationValue=0x00;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

if (HAL_RCC_OscConfig(&RCC_OscInitStruct)!= HAL_OK)

{

// Initialization Error

while(1);

}

 

/* Select MSI as system clock source and configure the HCLK, PCLK1 and PCLK2

clocks dividers */

RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);

RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;

RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

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

{

// Initialization Error

while(1);

}

 

// Enable Power Control clock

__HAL_RCC_PWR_CLK_ENABLE();

 

/* The voltage scaling allows optimizing the power consumption when the device is

clocked below the maximum system frequency, to update the voltage scaling value

regarding system frequency refer to product datasheet. */

__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);

}

 

JoaquimMartinez_0-1699626770389.png

 

0 REPLIES 0