I have configured the UART for multiprocessor communication over RS485. I can receive and transmit data correctly. After waking up (RWU=0) when the correct address is received subsequent bytes should be received normally, and not interpreted as another address is my understanding. But if the intended data bytes contains a '1' as MSB it is interpreted as an address. Now it is clear from the documentation that this is the correct behavior, but after the correct address is received (RWU set to 0 and RXNE set to 1, confirmed by debugging) I can only receive data with a value less than the defined address. For example, if I set wordlength to 9bit and the address to 4, the correct address will be 132 (10000100) which is expected (address length is 8 bit in this case I think, because ADDM7 is set). But subsequent bytes are still interpreted as addresses. Sending 132,55,45,150 (via RealTerm) will only receive 132,55,45 as 132 is the correct address and 44,55 has '0' as MSB. 150 is interpreted as a new address because of the '1' in the MSB and RWU is again set to 1 since it is the incorrect address and I can no longer receive data.
My question is how can i interpret subsequent bytes after an correct address as pure data bytes, before I go back to listening for an address again? If I understand correctly, RWU and RXNE is set by HW in this mode? Or is there something specific I should do in FW? My implementation is interrupt-based for now. The MCU I use is F303K8.
I'll attach some pictures, code and documentation for details and clarity.
Thanks!
Code and debug:
int main(void)
{
/* USER CODE BEGIN 1 */
testvar = testvar + 1;
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
HAL_UART_Transmit(&huart1, (uint8_t*)test, strlen(test), 100);
HAL_MultiProcessor_EnableMuteMode(&huart1);
HAL_MultiProcessor_EnterMuteMode(&huart1);
/* Listen for address */
if(HAL_UART_Receive_IT(&huart1, (uint8_t*)rx_buffer, BUFSIZE) != HAL_OK){
Error_Handler();
}
//HAL_MultiProcessor_EnterMuteMode(&huart1);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
//HAL_Delay(500);
//testvar = testvar + 1;
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
//testvar = 64;
/* ADDRESS received! Begin listening for data(COMMANDS)
* When CMDs handled, enter mute mode again in order to listen for address byte again */
if(HAL_UART_Receive_IT(&huart1, (uint8_t*)rx_buffer, BUFSIZE) != HAL_OK){
Error_Handler();
}
}