Forums

ARM RTX

Started by liem_ieie July 25, 2007
I am have a difficulty using serial in ARM RTX using Keil compiler. I
have simulated this program and work well. But when I flash to LPC2104
serial 0 only send 1 character to hyper terminal. Why this can happen?

Thank you.

main.c
#include
#include
#include

OS_TID terminal;

extern void Serial_Init (void);

void term (void) __task
{
puts("Hello World Hello World Hello World \r");
os_dly_wait (100);
}

void init_system (void) __task
{
//initialize system
Serial_Init();

//initialize task
terminal = os_tsk_create(term,0);
os_tsk_delete_self();
}

int main (void)
{
os_sys_init(init_system);
while(1);
}

serial.c
#include
#include
//declare RTX component
OS_TID wr_task;

void Serial_Interrupt (void) __irq
{
//RDR

//THRE
if (U0IIR&2)
{
a=U0IIR;
IODIR=0xFF00;
isr_evt_set (0x0100, wr_task);
}

VICVectAddr = 0; // Acknowledge Interrupt

}

void Serial_Init (void)
{
//setting GPIO for UART0 without FIFO
PINSEL0 |= 0x00000005;
PINSEL1 |= 0x00000000;
U0FCR = 0x00; //without FIFO
U0LCR = 0x83; //8 bits, no Parity, 1 Stop bit
U0DLL = 24; //baudrate 9600 for fpclk=(4915200/4)
U0DLM = 0;
U0LCR = 0x03; //DLAB=0
U1IER = 0x02; //transmit and receive interrupt
VICVectAddr0 = (unsigned int)Serial_Interrupt;
VICVectCntl0 = 0x26;
VICIntEnable |= 0x40;
}

int sendchar (int kar)
{
wr_task = os_tsk_self ();
os_evt_clr (0x0100, wr_task);
U0THR=(char) kar;
os_evt_wait_or (0x0100, 0xFFFF);
return kar;

/*U0THR=(char)kar;
while(!(U0LSR & (1<<6)));
return kar;*/
}

int getkey (void)
{
//while (!(U0LSR & 0x01));
return (U0RBR);
}

An Engineer's Guide to the LPC2100 Series

You may remove the "while(1)" in your main(), you also may add a
"os_tsk_delete_self()"
in term task or put the printf() and the delay in a while(1) loop.
In serial founctions, I wonder if the interrupt declaration is right. i work
on lpc2148 and for me,
the interrupt look like that :

/*interruption lors de la rtion sur l'UART 0*/
VICVectAddr9 = (U32)getkey_uart0;
VICVectCntl9 = 0x20 | 6;
VICIntEnable = 1<<6;
/*interruption lors de la rtion sur l'UART 1*/
VICVectAddr8 = (U32)getkey_uart1;
VICVectCntl8 = 0x20 | 7;
VICIntEnable = 1<<7;

but i only use the interrupt for the reception not for transmition.

I hope this will help you !
Romain

2007/7/25, liem_ieie :
>
> I am have a difficulty using serial in ARM RTX using Keil compiler. I
> have simulated this program and work well. But when I flash to LPC2104
> serial 0 only send 1 character to hyper terminal. Why this can happen?
>
> Thank you.
>
> main.c
> #include
> #include
> #include OS_TID terminal;
>
> extern void Serial_Init (void);
>
> void term (void) __task
> {
> puts("Hello World Hello World Hello World \r");
> os_dly_wait (100);
> }
>
> void init_system (void) __task
> {
> //initialize system
> Serial_Init();
>
> //initialize task
> terminal = os_tsk_create(term,0);
> os_tsk_delete_self();
> }
>
> int main (void)
> {
> os_sys_init(init_system);
> while(1);
> }
>
> serial.c
> #include
> #include //declare RTX component
> OS_TID wr_task;
>
> void Serial_Interrupt (void) __irq
> {
> //RDR
> //THRE
> if (U0IIR&2)
> {
> a=U0IIR;
> IODIR=0xFF00;
> isr_evt_set (0x0100, wr_task);
> }
>
> VICVectAddr = 0; // Acknowledge Interrupt
>
> }
>
> void Serial_Init (void)
> {
> //setting GPIO for UART0 without FIFO
> PINSEL0 |= 0x00000005;
> PINSEL1 |= 0x00000000;
> U0FCR = 0x00; //without FIFO
> U0LCR = 0x83; //8 bits, no Parity, 1 Stop bit
> U0DLL = 24; //baudrate 9600 for fpclk=(4915200/4)
> U0DLM = 0;
> U0LCR = 0x03; //DLAB=0
> U1IER = 0x02; //transmit and receive interrupt
> VICVectAddr0 = (unsigned int)Serial_Interrupt;
> VICVectCntl0 = 0x26;
> VICIntEnable |= 0x40;
> }
>
> int sendchar (int kar)
> {
> wr_task = os_tsk_self ();
> os_evt_clr (0x0100, wr_task);
> U0THR=(char) kar;
> os_evt_wait_or (0x0100, 0xFFFF);
> return kar;
>
> /*U0THR=(char)kar;
> while(!(U0LSR & (1<<6)));
> return kar;*/
> }
>
> int getkey (void)
> {
> //while (!(U0LSR & 0x01));
> return (U0RBR);
> }
>
>
>