Pumpkin, Inc.

Pumpkin User Forums

USART Communication using Salvo

For issues specific to TI's MSP430 line of ultra-low-power microcontrollers, including compilers (e.g. Quadravox AQ430), IDEs (e.g. IAR Embedded Workbench) and development tools (e.g. TI MSP-FET430 Flash Emulation Tool).

USART Communication using Salvo

Postby Syed Akbar » Fri Jun 24, 2005 9:55 am

Sir,
I have developed a Salvo application on IAR Embedded Workbecnh IDE for MSP430 V3 for USART communication between two MSP430F149 devices. I used two RS232(9pin) cables. One RS232 connects the computer and USART0 of device1. And the other connects the USART1 of device1 and USART1 of device2. Docklight terminal is used for data transmission and reception.

project1: UART01_ISR
This project programs device1 for USART communication using ISR. Options are set.
Source file: uart01_isr.c
/* This code, programs the device1 for USART Communication using ACLK and
baud rate = 2400.
Tasks are signalled from ISR using a Binary Semaphore.
*/


#include <main.h>
#include <salvo.h>
#include <msp430x14x.h>


#define TASK_USART0_RX_P OSTCBP(1) // Task 1 definition

#define TASK_USART1_RX_P OSTCBP(2) // Task 2 definition

#define BINSEM1_P OSECBP(1) // Event 1: Binary Semaphore


#define PRIO_USART0_RX 8 // Priority of Task1
#define PRIO_USART1_RX 10 // Priority of Task2


_OSLabel(usart0_rx_label) // Task1 label for context switch
_OSLabel(usart1_rx_label) // Task12 label for context switch


char tempBUF0; // Temporary Buffer
void USART0(); // Function to Initialize USART0
void USART1(); // Function to Initialize USART1

/* USART0() function initializes USART0 for 8 bit character, No parity
and 1 Stop Bit ( 8N1 Protocol). It selects and enables USART0 RXD/TXD pins.
ACLK with 32KHz is selected as USART clock source with baud rate 2400.
Baud rate = 2400
BRCLK = 32,768 (ACLK)
UBRx = 13, since the ideal divison factor is 13.65
UMCTLx = 6Bh
*/
void USART0(void)
{
//WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD
UCTL0 |= CHAR; // 8-bit character
UTCTL0 |= SSEL0; // UCLK = ACLK
UBR00 = 0x0D; // 32k/2400 - 13.65
UBR10 = 0x00; //
UMCTL0 = 0x6B; // Modulation
UCTL0 &= ~SWRST; // Initialize USART state machine
IE1 |= URXIE0; // Enable USART0 RX interrupt
}

/* USART1() function initializes USART1 for 8 bit character, No parity
and 1 Stop Bit ( 8N1 Protocol). It selects and enables USART1 RXD/TXD pins.
ACLK with 32KHz is selected as USART clock source with baud rate 2400.
Baud rate = 2400
BRCLK = 32,768 (ACLK)
UBRx = 13, since the ideal divison factor is 13.65
UMCTLx = 6Bh
*/
void USART1(void)
{
//WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P3SEL |= 0x30; // P3.4,5 = USART1 TXD/RXD
ME2 |= UTXE1 + URXE1; // Enable USART1 TXD/RXD
UCTL1 |= CHAR; // 8-bit character
UTCTL1 |= SSEL0; // UCLK = ACLK
UBR01 = 0x0D; // 32k/2400 - 13.6
UBR11 = 0x00; //
UMCTL1 = 0x6B; // Modulation
UCTL1 &= ~SWRST; // Initialize USART state machine
IE2 |= URXIE1; // Enable USART1 RX/TX interrupt
}

/* This task, signalled from ISR, perfroms the function of checking whether the TX Buffer
is ready, loads the contents of RXBUF0 to TXBUF0 and temporary buffer, tempBUF0.
*/

void usart0_rx(void)
{

while (!(IFG1 & UTXIFG0)); // USART0 TX buffer ready?
TXBUF0 = RXBUF0; // RXBUF0 to TXBUF0
tempBUF0 = RXBUF0; // RXBUF0 to tempBUF0
OS_WaitBinSem(BINSEM1_P, OSNO_TIMEOUT, usart0_rx_label); // Waits here forever until
// the task is sginalled by Semaphore
}

/* This task, signalled from ISR, perfroms the function of checking whether the TX Buffer
is ready, loads the contents of TXBUF0 to TXBUF1.
*/
void usart1_rx(void)
{

while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready?
TXBUF1 = TXBUF0; // TXBUF0 to TXBUF1
OS_WaitBinSem(BINSEM1_P, OSNO_TIMEOUT, usart1_rx_label); // Waits here forever until
// the task is signalled by Semaphore
}

void main(void)
{
Init(); // For Device Initialization
OSInit(); // Initializes all of Salvo's data structures,
// pointers, and counters.
InitPORT(); // Port Initialization
P1OUT = 0x00; // Set P1 to output direction
P1DIR = 0x03;
USART0(); // Calls function USART0() for USART0 Initialization
USART1(); // Calls function USART1() for USART1 Initialization
OSCreateTask(usart0_rx, TASK_USART0_RX_P, PRIO_USART0_RX); // Creates Task usart0_rx
OSCreateTask(usart1_rx, TASK_USART1_RX_P, PRIO_USART1_RX); // Creates Task usart1_rx
OSCreateBinSem(BINSEM1_P, 0); // Creates Binary Semaphore
OSEi(); // Enables Interrupts

for(;
OSSched(); // Multitasking
}

/* Interrupt Vector
*/
#pragma vector = UART0RX_VECTOR
__interrupt void usart0_rx_isr(void)
{
OSSignalBinSem(BINSEM1_P); // Signalling Binary Semaphore
OSSched();

}

configuration file: salvoconfig:uart01_isr.h

/* */
/* Salvo Pro source-code build */
/* */
#define OSBYTES_OF_DELAYS 1
#define OSENABLE_IDLING_HOOK TRUE

#define OSENABLE_BINARY_SEMAPHORES TRUE
#define OSEVENTS 1
#define OSTASKS 2

---------------------------------------------
Project2: UART11_ISR

Source file: uart11_isr.c

/* This code programs the device1 for USART Communication between two devices using ACLK and
baud rate = 2400.
Tasks are signalled from ISR using a Binary Semaphore.
*/

#include <main.h>
#include <salvo.h>
#include <msp430x14x.h>


#define TASK_USART1_RX_P OSTCBP(1) // Task 1 defintion
#define BINSEM1_P OSECBP(1) // Event 1: Binary Semaphore
#define PRIO_USART1_RX 6 // Priority of Task1

_OSLabel(usart1_rx_label) // Task1 label for context switch


void USART1();


/* USART1() function initializes USART1 for 8 bit character, No parity
and 1 Stop Bit ( 8N1 Protocol). It selects and enables USART1 RXD/TXD pins.
ACLK with 32KHz is selected as USART clock source with baud rate 2400.
Baud rate = 2400
BRCLK = 32,768 (ACLK)
UBRx = 13, since the ideal divison factor is 13.65
UMCTLx = 6Bh
*/
void USART1(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
ME2 |= UTXE1 + URXE1; // Enable USART0 TXD/RXD
UCTL1 |= CHAR; // 8-bit character
UTCTL1 |= SSEL0; // UCLK = ACLK
UBR01 = 0x0D; // 32k/2400 - 13.65
UBR11 = 0x00; //
UMCTL1 = 0x6B; // Modulation
UCTL1 &= ~SWRST; // Initialize USART state machine
IE2 |= URXIE1; // Enable USART0 RX interrupt
}

/* This task performs the function of checking whether the USART1 TX buffer is ready and loads
the contents of RXBUF1 to TXBUF1
*/
void usart1_rx(void)
{


while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready?
TXBUF1 = RXBUF1; // RXBUF1to TXBUF1

OS_WaitBinSem(BINSEM1_P, OSNO_TIMEOUT,usart1_rx_label); // waits forever until the task is
// signalled by semaphore

}

void main(void)
{
Init(); // For Device Initialization
OSInit(); // Initializes all of Salvo's data structures,
// pointers, and counters.
InitPORT(); // Port Initialization
P1OUT = 0x00; // Set P1 to output direction
P1DIR = 0x03;
USART1(); // Calls function USART1() for USART1 Initialization
OSCreateTask(usart1_rx, TASK_USART1_RX_P, PRIO_USART1_RX); // Creates Task usart1_rx
OSCreateBinSem(BINSEM1_P, 0); // Creates Binary Semaphore
OSEi(); // Enables Interrupts
for(;
OSSched(); // Multitasking
}

/* Interrupt Vector
*/
#pragma vector = UART1RX_VECTOR
__interrupt void usart1_rx_isr(void)
{
OSSignalBinSem(BINSEM1_P); // Signalling Binary Semaphore
OSSched();
}

Configuration file: salvoconfig_uart11_isr.h

/* */
/* Salvo Pro source-code build */
/* */
#define OSBYTES_OF_DELAYS 1
#define OSENABLE_IDLING_HOOK TRUE

#define OSENABLE_BINARY_SEMAPHORES TRUE
#define OSEVENTS 1
#define OSTASKS 1
---------------------------------------------
Device1 is programmed with UART01_ISR and device2 is programmed with UART11_ISR. There are no compiling and Building errors. JTAG Debugger is connected to device1. device1 and device2 are connected using RS232 with USART1 on device1 and USART1 on device2. DockilightV1.4 Terminal is opened and Communication settings are set for 2400 baudrate, 8 data bits, No Parity and 1 Stop Bit. Communication port is opened. And when a character is transmitted and program is run in the dedugger, it is observed that the character is echoed back continously until the program is stopped.
The terminal results:
[TX] - b
[RX] - bbbbbbbbbbbbbbbbbbbbbb(continous reception until the program is stopped)

----------------------------------------
I have tried every possibility to verify the application. When i have implemented this program without using ISR, everything seemed to be fine and i have obtained the desired results. But using ISR, i couldnt. Can you please try to solve my problem. I will be very grateful to you.
I appreciate your recommendations.
Thank You
- Syed Akbar

------------------
Akbar

Akbar
Syed Akbar
 
Posts: 13
Joined: Sun May 22, 2005 11:00 pm
Location: Bremen, Bremen, Germany

Re: USART Communication using Salvo

Postby aek » Fri Jun 24, 2005 10:14 am

Hi Syed.

code:
/* Interrupt Vector
*/
#pragma vector = UART0RX_VECTOR
__interrupt void usart0_rx_isr(void)
{
OSSignalBinSem(BINSEM1_P); // Signalling Binary Semaphore
OSSched();

}


STOP! OSSched() cannot be called from an ISR! That will break everything. Call OSSched() only from main().

Send an email to support with your request, and I'll email you the MSP430 USART code we use in our CubeSat products (http://www.cubesatkit.com). It works flawlessly.

Note that our CubeSat Kit customers primarily use the Rowley compiler, and so there are some minor differences ...

------------------

[This message has been edited by aek (edited June 24, 2005).]

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: USART Communication using Salvo

Postby Syed Akbar » Mon Jun 27, 2005 1:15 am

Sir,
Thank you very much for your immediate response. I have removed OSSched() from the ISR. And used only in main(). But the same problem persisted. When i have transmitted a character, the same character is received back continously until unless the program is terminated when debugged. the terminal results:
[Tx] - a
[Rx] - aaaaaaaaaaaaaaaaaaaaaaaaaaaa

Thank you
--Syed Akbar

------------------
Akbar

Akbar
Syed Akbar
 
Posts: 13
Joined: Sun May 22, 2005 11:00 pm
Location: Bremen, Bremen, Germany

Re: USART Communication using Salvo

Postby aek » Mon Jun 27, 2005 3:11 am

Hi Syed.

I emailed you the files ...

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: USART Communication using Salvo

Postby karpion » Sat Nov 01, 2008 9:23 am

quote:
Originally posted by aek:
Hi Syed.

I emailed you the files ...


hi, could you send me an email with rs232 code for cubesatkit development please?I'm workin on that kit and I've tried to implement some different code but at the moment I'm not able to receive anything right from rs232 via hyperterminal..thanks a lot

roberto
karpion @ hotmail.com

.k@r4ion.
karpion
 
Posts: 4
Joined: Mon Mar 03, 2008 12:00 am
Location: Italy

Re: USART Communication using Salvo

Postby aek » Sat Nov 01, 2008 11:10 am

Hi Roberto.

1) The CSK UART code is contained in the Test1 program.

2) Alternatively, you can use http://www.pumpkininc.com/library/msp430/library-msp430-1.2.2-rc0.exe . These have not yet been incorporated into the CSK code, but they are well-used and stable.

--Andrew

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: USART Communication using Salvo

Postby karpion » Tue Nov 04, 2008 1:36 am

Hi, I read all the *.c sources files that you sent me but I've got a question..every file contains an #include config.h but I couldn't recognize it in these folders (I mean Src and Inc) and without it every debug fails. Please forgive me to be only a beginner..

thanks
Roberto

quote:
Originally posted by aek:
Hi Roberto.

1) The CSK UART code is contained in the Test1 program.

2) Alternatively, you can use http://www.pumpkininc.com/library/msp430/library-msp430-1.2.2-rc0.exe . These have not yet been incorporated into the CSK code, but they are well-used and stable.

--Andrew


.k@r4ion.
karpion
 
Posts: 4
Joined: Mon Mar 03, 2008 12:00 am
Location: Italy


Return to TI's MSP430

Who is online

Users browsing this forum: No registered users and 0 guests

cron