Page 1 of 1

uart Freemodbus question

Posted: Thu Apr 04, 2013 6:44 am
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

Re: uart Freemodbus question

Posted: Thu Apr 04, 2013 8:23 am
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

Re: uart Freemodbus question

Posted: Thu Apr 04, 2013 9:08 am
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);
}

Re: uart Freemodbus question

Posted: Thu Apr 04, 2013 9:11 am
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