cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 UART problem - receiving DMX / RS-485

Jan Weinands
Associate
Posted on May 02, 2017 at 12:06

Dear All,

I have some problems with receiving DMX-512 data on a STM32F103RB.

I am using mbed and the library i found for this is meant for the F303 version.

When i look at the Typedef _uart there is a difference in those 2 chips in the uart registers.

void

 DMX::int_rx () {     

int

 flg, dat;       

#ifdef TARGET_STM

        

dat = _dmx.

getc

();         

flg = (_uart->ISR & (USART_FLAG_FE | USART_ISR_IDLE)) == (USART_FLAG_FE | USART_ISR_IDLE);         

if

 (flg) {             

_uart->ICR = USART_ICR_FECF;         

}

Since ISR and ICR are not in that typedef i get errors on the flag, but i don't know how i can fix this.

Could anyone help me with this?

Thank you in advance!

3 REPLIES 3
AvaTar
Lead
Posted on May 02, 2017 at 14:00

What is your DMX software based on, in regard to STM ?

In the SPL for the F30x, those registers still exist. A snippet from stm32f30x.h:

typedef struct

{

  __IO uint32_t CR1;  /*!< USART Control register 1,    Address offset: 0x00 */

  __IO uint32_t CR2;    /*!< USART Control register 2,  Address offset: 0x04 */

  __IO uint32_t CR3;    /*!< USART Control register 3,  Address offset: 0x08 */

  __IO uint16_t BRR;    /*!< USART Baud rate register,  Address offset: 0x0C */

...

  __IO uint32_t

ISR

;    /*!< USART Interrupt and status register,  Address offset: 0x1C */

  __IO uint32_t

ICR

;    /*!< USART Interrupt flag Clear register, Address offset: 0x20 */

  __IO uint16_t RDR;    /*!< USART Receive Data register, Address offset: 0x24 */

  uint16_t  RESERVED4;  /*!< Reserved, 0x26 */

  __IO uint16_t TDR;    /*!< USART Transmit Data register,  Address offset: 0x28 */

  uint16_t  RESERVED5;  /*!< Reserved, 0x2A   */

} USART_TypeDef;

And, instances are declared in capital letters in the same file:

#define USART2      ((USART_TypeDef *) USART2_BASE)

#define USART3      ((USART_TypeDef *) USART3_BASE)

#define UART4       ((USART_TypeDef *) UART4_BASE)

#define UART5       ((USART_TypeDef *) UART5_BASE)

...

Seems you need to re-write some parts ...

Jan Weinands
Associate
Posted on May 02, 2017 at 14:51

Yes I know they are available for the STM32F30x stuff, but I am using the STM32F103.

So in that SPL they are not available, but what can i use for those registers?

Posted on May 02, 2017 at 15:40

Ahh, got the porting direction wrong.

The F10x has a different register interface (to the USART peripheral and other peripherals):

typedef struct

{

  __IO uint16_t   SR;

  uint16_t        RESERVED0;

  __IO uint16_t   DR;

  uint16_t        RESERVED1;

  __IO uint16_t   BRR;

  uint16_t        RESERVED2;

  __IO uint16_t   CR1;

  uint16_t        RESERVED3;

  __IO uint16_t   CR2;

  uint16_t        RESERVED4;

  __IO uint16_t   CR3;

  uint16_t        RESERVED5;

  __IO uint16_t   GTPR;

  uint16_t        RESERVED6;

} USART_TypeDef;

That probably means a re-write of several sections. Not sure about mbed and available libraries, I never used it.