cancel
Showing results for 
Search instead for 
Did you mean: 

Are there any STMF0 examples available for the USART address mark detection wakeup?

NSharp
Associate II

I can find examples in the STMF0 Cube folders for wakeup from STOP for various peripherals; however, I cannot find any examples of address mark detection wakeup for USART.

I have attempted to implement the address mark detection wakeup via the description in the STMF0 Reference Manual, Section 27.5.7. And, I have attempted to implement my project via the code references I can find in the stm32f0xx_hal_uart.c and stm32f0xx_hal_uart_ex.c (which are few). However, the HAL_UARTEx_WakeupCallback() is never called, and the interrupts never stop reception of data. So, I cannot seem to figure out what isn't being setup correctly.

In my USART init function, I am setting up my word length to be 9 bits; I am disabling MSBFIRST; and, I am using the HAL_MultiProcessor_Init() function to setup the address mark wakeup method. I assume, since there is no separate "SetAddress()" function, that this is the way to set the device address:

  huart1.Instance = USART1;
  huart1.Init.BaudRate = 115200;
  huart1.Init.WordLength = UART_WORDLENGTH_9B;
  huart1.Init.StopBits = UART_STOPBITS_1;
  huart1.Init.Parity = UART_PARITY_NONE;
  huart1.Init.Mode = UART_MODE_TX_RX;
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
 
  huart1.AdvancedInit.MSBFirst = UART_ADVFEATURE_MSBFIRST_DISABLE;
  huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_MSBFIRST_INIT;
 
  if (HAL_MultiProcessor_Init(&huart1, 0x00, UART_WAKEUPMETHOD_ADDRESSMARK) != HAL_OK)
  {
    Error_Handler();
  } else {
    HAL_MultiProcessorEx_AddressLength_Set(&huart1, UART_ADDRESS_DETECT_7B);
    HAL_MultiProcessor_EnableMuteMode(&huart1);
 
    HAL_MultiProcessor_EnterMuteMode(&huart1); // Tried with and without this line
  }

Then, I setup my interrupt for USART1 and call HAL_UART_Receive_IT() to start receiving.

However, my HAL_UARTEx_WakeupCallback() function is never called. I get callbacks to HAL_UART_RxCpltCallback() constantly.

Is there any example for multiprocessor UART communication using the address mark detection?

Thanks for any help in advance.

5 REPLIES 5

Read out and check/post the relevant USART registers' content. Observe, how USART_ISR.RWU reacts on various bytes incoming to the Rx pin.

JW

NSharp
Associate II

JW,

Thanks for the suggestion. I can see the following set when I receive an interrupt callback in HAL_UART_RxCpltCallback():

USART_CR1->CMIE (Character match interrupt enable) = 0 (character match not enabled)

USART_CR1->MME (Mute mode enable) = 1 (can switch between mute and active mode)

USART_CR1->WAKE (Wakeup mode) = 1 (address mark wakeup method)

USART_CR2->ADD[7:0] (USART address) = 0x00 (device address)

USART_CR2->ADDM7 (Address bits) = 1 (8 address bits for 9-bit USART comms)

USART_CR3->WUS[1:0] (Wakeup from stop mode interrupt flag) = 0x00 (address mark wakeup)

USART_CR3->WUFIE (Wakeup from stop mode interrupt enabled) = 0 (interrupt not enabled)

USART_RQR->MMRQ (Mute mode request) = 0 (not currently in mute mode)

USART_ISR->WUF (Wakeup from stop mode flag) = 0 (wakeup event not detected)

USART_ISR->RWU (Receiver wakeup from mute mode flag) = 0 (receiver in active mode)

USART_ISR->CMF (Character match flag) = 1 (device address matched)

USART_ISR->RXNE (Read data register not empty) = 1 (data ready to read)

Most of these never change, with the one exception of the RXNE flag changing between 0 and 1, occasionally.

If USART_ISR.RWU does not change, the receiver did not see address different from its own (i.e. a 9-bit word with MSB set but different from 0x100, i.e. 0x1xx).

How do you generate the 9-bit data for Rx? Do you observe them using LA/oscilloscope directly on the Rx pin? Is the baudrate correct?

JW

Guenael Cadier
ST Employee

Dear @NSharp​

As mentioned by @Community member​ , please ensure your MSB of sent adress value is 1, in order to be interpreted as an address.

(In 9-bit data modes, address detection is done on 8-LSB bit address with MSB set to 1).

Regards

Guenael

NSharp
Associate II

The 9-bit data is generated by legacy hardware that has been working for years; so, I am confident that part is working. The baud rate is correct (115,200).

I can see the bit being set, to indicate that the transmission is an address byte:

0690X00000Bwl4UQAR.png

In this example from my logic analyzer, I see the start bit go low (0), and then 8 bits of data are transferred (LSB -> MSB) as 0xFF. The last 2 bits are the address mark bit (1) and the stop bit (1). So, in this case, I should see the STMF0 detect the address packet and compare it to the configured device (USART) address, which is 0x00. The USART should go into mute mode at this point, right? And, if a message comes through as 0x000 0000 0011 (matches my device address of 0x00), then I should get an interrupt and callback to the WakeupCallback(), correct?