uart Freemodbus question

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

Moderators: RoccoMarco, barthess

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

uart Freemodbus question

Postby DeusExMachina » Thu Apr 04, 2013 6:44 am

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: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: uart Freemodbus question

Postby Giovanni » Thu Apr 04, 2013 8:23 am

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
Location: South Korea
Has thanked: 3 times
Been thanked: 3 times

Re: uart Freemodbus question

Postby DeusExMachina » Thu Apr 04, 2013 9:08 am

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: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: uart Freemodbus question

Postby Giovanni » Thu Apr 04, 2013 9:11 am

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


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 34 guests