uart Freemodbus question

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

uart Freemodbus question

Post by DeusExMachina »

I am porting FreeModbus to stmF4
I need to create function enabling/disable RX/TX interrupts for uart like this (code for st8)

Code: Select all

void
vMBPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable )
{
  /* If xRXEnable enable serial receive interrupts. If xTxENable enable
  * transmitter empty interrupts.
  */
  if(xRxEnable == TRUE)
  {
    USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
  }
  else
  {
    USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
  }
 
  if(xTxEnable == TRUE)
  {
    USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
  }
  else
  {
    USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
  }
}

How can I enable/disable interrupts using uart driver API? I don't want to modify registers directly
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: uart Freemodbus question

Post by Giovanni »

Hi,

You can't, the UART API does not handle interrupts, the driver is an abstraction so you should not expect it to expose as API low level details.

You should keep using the ST lib or reimplement the modbus module using the high level API.

Giovanni
User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

Re: uart Freemodbus question

Post by DeusExMachina »

I made like this, but I'm afraid to interfier driver state machine

Code: Select all

void vMBPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable )
{
   /* If xRXEnable enable serial receive interrupts. If xTxENable enable
    * transmitter empty interrupts.
    */
   uartStop(&UARTD1);

   if(xRxEnable == TRUE)
   {
      uart_conf.cr1 |= USART_CR1_RXNEIE;
   }
   else
   {
      uart_conf.cr1 &= ~USART_CR1_RXNEIE;
   }

   if(xTxEnable == TRUE)
   {
      uart_conf.cr1 |= USART_CR1_TXEIE;
   }
   else
   {
      uart_conf.cr1 &= ~USART_CR1_TXEIE;
   }
   uartStart(&UARTD1, &uart_conf);
}
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: uart Freemodbus question

Post by Giovanni »

It will create problems for sure.

I general, when using the UART driver, I don't see any reason to change interrupt settings, you should focus on the protocol you want to implement not on the low level details.

Giovanni
Post Reply