cancel
Showing results for 
Search instead for 
Did you mean: 

Uart 2

Posted on June 03, 2010 at 11:55

Hi there,

I spent the entire day yesterday trying yet again to get the sample code (UM0884) to compile. For some reason I am struggling to understand the code that has been written as a worked example, there seems to be way too many header files and source files required just to turn on the RS232 Serial Comms...

In the past everytime I wanted to use the serial comms on processors such as the PIC, Motorola, NEC, Atmel the process was fairly simple and straightforward and could be made to work in an hour or so, after some tweaking of the baud rate etc...

Do I need to use all the headerfiles and source files to get basic comms up and running or can I directly turn on the Uart 2 directly?

Basically what I am asking is can I do it like this?

void UART2_Init (void)

{

 UART2_CR1 = 0x02;      // 1 start bit, 8 data, odd parity

 UART2_CR3 = 0x20;      // 2 Stop Bits

 UART2_BRR2 = 0x02;   // Baud Rate

 UART2_BRR1 = 0x68;   // Baud Rate

 UART2_CR2 = 0x80;     // Set TEN bit to Enable Transmitter Mode

// set a flag to watch for TC to be set to 1 in UART_SR

}

As this is how I always used to initialise the Serial Comms, can I still do it this way?

I understand to talk out other commands are required, but I already understand how that should be done...
7 REPLIES 7
Grom
Associate II
Posted on June 14, 2010 at 12:20

Hy Icarus,

Sorry for this late reply.

Yes you can use this way to setup the UART 2 instead of using the library function. You just have to include  ''stm8s.h'' file in your project and use the defined UART2 struct

example :

    ''UART2->CR1 = 0x02;''      // 1 start bit, 8 data, odd parity

If you are familiar with microcontrolers , It's for sure better to use this way of programing instead of Libraries .

By the way , We have developed   by our side  one example (without libraries ;) ) using Hyperterminal + temp sensor. this example is not yet published but I can provide you our sources.

Rgds

Grom

danielfischer9
Associate II
Posted on June 14, 2010 at 17:40

Hello Grom,

I would like to get your UART + A/D (temp sensor) example, if would not mind sharing it with me.

I have been spending tons of time fighting with trying to get the Cosmic / Raisonance toolsets to work; last night (3AM my time), someone at Cosmic took pitty on me and told us what must be done to get their linker to be able to handle more than 256 bytes of data.  I have managed to get the STM examples to compile (all use very little data, so the data size limitation showed up only when I created an array to save some A/D samples into), but could use your example if available.

One more question; I use the STVD environment; if I go into Tools/Options/Toolset, then select the toolset (Cosmic or Raisonance), point to where the executables are (in the bin entry), I always get a warning about ''Toolset rootpaths have not been specified for at least one of the supported toolsets.  Confirm.....''.  With Cosmic, I hit ok to confirm god knows what, and the compile/link seems to work ok.  With Raisonance, I hit the same OK, it tells me many more times the same thing (ie the warning does not go away), but eventually it does.  It also seems to compile / link ok. 

Can you make any sense of all this?

I find the whole software package (STVD + compiler/linker) terrible.  The only reason for my spending so much time on this board, is because of the low price + the background debugger which comes on the board.  But even then, I dread what is going to happen when my almost 100 students will be asked to program using these tools, and I will become the lightning rod for their frustration.

Anyway, if you do not mind sharing your code, I would like to learn from it.  I do not know if you can post it as an attachment to this board, if not could you please email it to me at fischerd@idirect.ca.

Thanks

Daniel

col_kerr
Associate II
Posted on June 20, 2010 at 22:30

Hi Grom,

I read about the hyperterminal temperature code and would like to save myself a lot of time working it all out, so if you could let me know how to find a copy it would be very helpfull.

I have just got Hyperterminal example to run after swapping the tx and rx lines.

A simple start example would be a good idea with just 9600 8N1 and without all the frills. 

Cheers

Col Kerr

uthenb
Associate II
Posted on June 24, 2010 at 21:48

I complete code communication to hyper

http://www.10logic.com/download/HyperterminalStm8s.rar

. and i'm try using uart2 interrupt in this [DEAD LINK /public/STe2ecommunities/mcu/Lists/STM8SDiscovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM8SDiscovery/UART2 Interrupt&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000CCDF802E596CAF44ADED5E61F5CA8B1B&currentviews=11]link

Ok in my project im use stm8s drive 7 segment . i'm try receive data from hyper with interrupt it' not work

help me

ting
Associate II
Posted on July 16, 2010 at 07:13

Grom,

May I have a copy of your UART2-temperature sensing code?  I got HyperTerminal project working, but could not bring up UART2 on my own.  I configured UART2 exactly as in HyperTerminal project, but UART2 would not send or receive characters.  What other devices do I have to configure correctly before UART2 does its job?

I am trying to bring up a FORTH interpreter on STM8S.  Once I get FORTH going, there is no need of C compilers and all the complication they bring in.

Thanks,

Ting.

ting
Associate II
Posted on July 18, 2010 at 01:23

Icarus,

I tried these init code on Discovery.  They worked.  However, I past only assembly code.  You can write them in C.

        MOV     PD_DDR,#$1  ; LED, SWIM

        MOV     PD_CR1,#$3  ; pullups

        MOV     PD_CR2,#$1  ; speed

        MOV     UARTBD2,#$00  ;9600 baud

        MOV     UARTBD1,#$0d  ;9600 baud

        MOV     UARTCR1,#$06  ;8 data bits, no parity

        MOV     UARTCR3,#$00  ;1 stop bit

        MOV     UARTCR2,#$0C  ;enable tx & rx

To receive:

QKEY:

        BTJF UARTSR,#5,QKEY   ;check status

        LD    A,UARTDR   ;get char in A

To transmit:

OUTPUT:  BTJF UARTSR,#7,OUTPUT  ;loop until tdre

        LD    UARTDR,A   ;send A

Good luck.

Ting.

By the way, my FORTH interpreter is working.  If you are interested, send an email to me: ting@offete.com.

ting
Associate II
Posted on July 19, 2010 at 07:10

Hello,

I was wondering about the UART2 baudrate divider of $70 in my prior experiment.  It should be $682 for the 16 MHz clock.  It turns out that STM6S boots up with the internal 2 MHz clock.  The external clock has to be switched on to run at 16 MHz.  Here are code which initialize Port D, external clock, and UART2 port for 9600 baud operation.

Good luck,

Ting.

        MOV     PD_DDR,#$1  ; LED, SWIM

        MOV     PD_CR1,#$3  ; pullups

        MOV     PD_CR2,#$1  ; speed

 BSET CLK_SWCR,#1 ; enable external clcok

 MOV CLK_SWR,#$B4 ; external cyrstal clock

WAIT0: BTJF CLK_SWCR,#3,WAIT0 ; wait SWIF

        BRES CLK_SWCR,#3 ; clear SWIF

 MOV     UARTBD2,#$02  ;9600 baud

        MOV     UARTBD1,#$68  ;9600 baud

        MOV     UARTCR1,#$06  ;8 data bits, no parity

        MOV     UARTCR3,#$00  ;1 stop bit

        MOV     UARTCR2,#$0C  ;enable tx & rx