uart problems with atmel 90s8515

Started by myemfthesis January 6, 2004
hi guys! i'm eugene and i'm relatively a beginner in mcus and mcu
programming. i would like to ask for your help regarding my simple
problem. i'm trying to program my atmel 90s8515 mcu to send data to
the uart for every 5 seconds. i've set-up my timer/counter registers
so that the mcu would raise an interrupt for every 5 seconds. but
the problem is that when the program finishes executing the
send_GHWSW_command interrupt handler routine (the routine that is
executed when a iv_TIMER1_COMPB interrupt occurs) it goes back to my
start up routine. i used the atmel avr studio 4 to debug my program.
i would appreciate any help from you guys! thanks!

i hope that i've stated my problem clearly. if not then please tell
so that i could restate my problems more clearly. i've included my
mcu code here.

/*
program: chk3310_1.c
description: sends a "Get Hardware and Software" command to the
nokia 3310 cellphone
through the UART.
*/

#include "io8515v.h"
#include "string.h"
#include "macros.h"
#include "stdio.h"

#pragma interrupt_handler send_GHWSW_command:iv_TIMER1_COMPB
//send command every 5 seconds
//acts as a keepalive routine
//compare timer/counter1 with ocrb register
#pragma interrupt_handler rx_receive:iv_UART_RX
//lights up leds if data was received from nokia 3310

//function prototypes
void synchronize(void);
void start_up(void);
void rx_receive(void); //synchronization character array
unsigned char csync[128] =
{0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x5
5,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x
55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0
x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x5
5,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
,0x55,0x55,
0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
,0x55,0x55};

//get hardware and software version

unsigned char hwsw[16] =
{0x1E,0x00,0x0C,0xD1,0x00,0x07,0x00,0x01,0x00,0x03,0x00,
0x01,0x60,0x00,0x72,0xD5};

//stores the data from the cellphone

unsigned char data[255];

static int hwsw_charcount = sizeof(hwsw);
static int csync_charcount = sizeof(csync); void start_up(void){
SREG=0x00; //disable interrupts first
GIMSK=0x00; //disable external interrputs
PORTB=0xff; //turn portb off
DDRB=0xff; //configure portb for output
PORTA=0xff; //enable internal pull-ups
DDRA=0x00; //configure porta for input
MCUCR=0x0f;
TCCR1A=0;
TCCR1B=0x05;//clk/1024 clk = 3.68mhz
//OCR1AH=0xff; // 1024/3.68mhz = 2.78e-4 sec * 65535 = 17
sec
//OCR1AL=0xff; //raises a timer interrupt every 17 seconds
//OCR1BH=0x46; // 1024/3.68mhz = 2.78e-4 sec * 18000 = 5 sec
//OCR1BL=0x50; // raises interrupt every 5 seconds
OCR1BH=0x00; // for debugging purposes
OCR1BL=0x02; // raises interrupt every 5.56e-4 seconds

UCR=0x00;//disable when setting baud rate
UBRR=1; //baud set to 115200 at 3.68mhz
UCR=0xc8;//enable ucr
USR=0x20;
synchronize();
TCNT1H=0; //start counting from 0
TCNT1L=0;
SREG=0x80; //enable global interrupts
GIMSK=0xc0; //enable external interrupts
TIMSK=0xa0;
} void synchronize(void){
static int tmp2=0;
unsigned char tmpchar;
for(tmp2=0;tmp2<=csync_charcount-1;tmp2++){
putchar(csync[tmp2]);
tmpchar=csync[tmp2];
//PORTB = ~tmp2;
}
}

void send_GHWSW_command(void){
static int tmp1=0;
unsigned char tmpchar;
//PORTB=0xff;
for(tmp1=0;tmp1<=hwsw_charcount-1;tmp1++){
putchar(/*tmpchar*/hwsw[tmp1]);
tmpchar=hwsw[tmp1];
}
TCNT1H=0; //manually reset timer/counter1
TCNT1L=0;
} void rx_receive(void){
//test
static int counter=0;
PORTB=0x55;
}

int main(void){
start_up();
while(1){
//infinite loop
}
return 0;
}



Hi

I havn't looked at how you've set the IRQ's up fully but it doesn't
look a million miles off. You may well get into the IRQ routine but
you need read the UDR in the RXIRQ routine. From memory, if the RXIRQ
flag is still set when you RTI then makes sense thats where the next
IRQ will come from. Reading the UDR clears the RXIRQ flag.

Rgds

--- In avrclub@avrc..., "myemfthesis" <myemfthesis@y...>
wrote:
> hi guys! i'm eugene and i'm relatively a beginner in mcus and mcu
> programming. i would like to ask for your help regarding my simple
> problem. i'm trying to program my atmel 90s8515 mcu to send data to
> the uart for every 5 seconds. i've set-up my timer/counter
registers
> so that the mcu would raise an interrupt for every 5 seconds. but
> the problem is that when the program finishes executing the
> send_GHWSW_command interrupt handler routine (the routine that is
> executed when a iv_TIMER1_COMPB interrupt occurs) it goes back to
my
> start up routine. i used the atmel avr studio 4 to debug my
program.
> i would appreciate any help from you guys! thanks!
>
> i hope that i've stated my problem clearly. if not then please tell
> so that i could restate my problems more clearly. i've included my
> mcu code here.
>
> /*
> program: chk3310_1.c
> description: sends a "Get Hardware and Software" command to the
> nokia 3310 cellphone
> through the UART.
> */
>
> #include "io8515v.h"
> #include "string.h"
> #include "macros.h"
> #include "stdio.h"
>
> #pragma interrupt_handler send_GHWSW_command:iv_TIMER1_COMPB
> //send command every 5 seconds
> //acts as a keepalive routine
> //compare timer/counter1 with ocrb register
> #pragma interrupt_handler rx_receive:iv_UART_RX
> //lights up leds if data was received from nokia 3310
>
> //function prototypes
> void synchronize(void);
> void start_up(void);
> void rx_receive(void); > //synchronization character array
> unsigned char csync[128] =
>
{0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x5
>
5,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x
>
55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0
>
x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
>
0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
> ,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x
5
>
5,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
>
0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
> ,0x55,0x55,
>
0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
> ,0x55,0x55};
>
> //get hardware and software version
>
> unsigned char hwsw[16] =
> {0x1E,0x00,0x0C,0xD1,0x00,0x07,0x00,0x01,0x00,0x03,0x00,
> 0x01,0x60,0x00,0x72,0xD5};
>
> //stores the data from the cellphone
>
> unsigned char data[255];
>
> static int hwsw_charcount = sizeof(hwsw);
> static int csync_charcount = sizeof(csync); > void start_up(void){
> SREG=0x00; //disable interrupts first
> GIMSK=0x00; //disable external interrputs
> PORTB=0xff; //turn portb off
> DDRB=0xff; //configure portb for output
> PORTA=0xff; //enable internal pull-ups
> DDRA=0x00; //configure porta for input
> MCUCR=0x0f;
> TCCR1A=0;
> TCCR1B=0x05;//clk/1024 clk = 3.68mhz
> //OCR1AH=0xff; // 1024/3.68mhz = 2.78e-4 sec * 65535 = 17
> sec
> //OCR1AL=0xff; //raises a timer interrupt every 17 seconds
> //OCR1BH=0x46; // 1024/3.68mhz = 2.78e-4 sec * 18000 = 5 sec
> //OCR1BL=0x50; // raises interrupt every 5 seconds
> OCR1BH=0x00; // for debugging purposes
> OCR1BL=0x02; // raises interrupt every 5.56e-4 seconds
>
> UCR=0x00;//disable when setting baud rate
> UBRR=1; //baud set to 115200 at 3.68mhz
> UCR=0xc8;//enable ucr
> USR=0x20;
> synchronize();
> TCNT1H=0; //start counting from 0
> TCNT1L=0;
> SREG=0x80; //enable global interrupts
> GIMSK=0xc0; //enable external interrupts
> TIMSK=0xa0;
> } > void synchronize(void){
> static int tmp2=0;
> unsigned char tmpchar;
> for(tmp2=0;tmp2<=csync_charcount-1;tmp2++){
> putchar(csync[tmp2]);
> tmpchar=csync[tmp2];
> //PORTB = ~tmp2;
> }
> }
>
> void send_GHWSW_command(void){
> static int tmp1=0;
> unsigned char tmpchar;
> //PORTB=0xff;
> for(tmp1=0;tmp1<=hwsw_charcount-1;tmp1++){
> putchar(/*tmpchar*/hwsw[tmp1]);
> tmpchar=hwsw[tmp1];
> }
> TCNT1H=0; //manually reset timer/counter1
> TCNT1L=0;
> } > void rx_receive(void){
> //test
> static int counter=0;
> PORTB=0x55;
> }
>
> int main(void){
> start_up();
> while(1){
> //infinite loop
> }
> return 0;
> }




hi all
i think that u forget to intilaiz the stak pointer to the end of the internal RAM
find the address of the last location and make the value of the stak pointer equal that
take care that the stak is a two byte regestar
---------------------------------