ATmega-162 UART sms code using circular buffer(Procyon libr)

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello friends, need a little help with programming.

I have written a SMS sending program in ATmega162, firstly I used normal usart functions(which worked fine), and then I tried to put the same commands in a circular buffer and transmitted the buffer but no sms is being received.

I used the procyon avr library's implementation of circular buffer.

I don't get any errors or warnings in my program. I don't know whats wrong.

/* Program for Vehicle Tracking System*/

#define F_CPU 8000000
#define USART0_BAUDRATE 9600
#define BAUD0_PRESCALE ((( F_CPU / ( USART0_BAUDRATE * 16UL))) - 1)

#define USART1_BAUDRATE 9600
#define BAUD1_PRESCALE ((( F_CPU / ( USART1_BAUDRATE * 16UL))) - 1)

#include 
#include 
#include 
#include 
#include 
#include 
#include 

void USART0_Init()
{
/* Set baud rate USART0 */
UBRR0H = ( BAUD0_PRESCALE >> 8);
UBRR0L = BAUD0_PRESCALE ;

/* USART0 - Enable receiver and transmitter */
UCSR0B= (1<<RXEN0)|(1<<TXEN0);
/* Set frame format: 8data---ucsz0=1,ucsz1=1, 1stop bit ---usbs=0*/
UCSR0C = (1 << URSEL0)|(3<<UCSZ00);
}

// USART0 - Transmission
void USART0_Transmit( unsigned char data )
{
/* USART0 Wait for empty transmit buffer */
while ( !( UCSR0A & (1<<UDRE0)) );
/* USART0 Put data into buffer, sends the data */
UDR0 = data;
}

//USART0 RX
unsigned char USART0_Receive( void )
{
while (!(UCSR0A & (1 << RXC0)) ); // Do nothing until data have been recieved and is ready to be read from UDR
return(UDR0); // return the byte  
}

void USART1_Init()
{
/* Set baud rate USART0 */
UBRR1H = ( BAUD1_PRESCALE >> 8);
UBRR1L = BAUD1_PRESCALE ;

/* USART0 - Enable receiver and transmitter */
UCSR1B= (1<<RXEN1)|(1<<TXEN1);
/* Set frame format: 8data---ucsz0=1,ucsz1=1, 1stop bit ---usbs=0*/
UCSR1C = (1 << URSEL1)|(3<<UCSZ10); /**/
}

// USART0 - Transmission
void USART1_Transmit( unsigned char data )
{
/* USART0 Wait for empty transmit buffer */
while ( !( UCSR1A & (1<<UDRE1)) );
/* USART0 Put data into buffer, sends the data */
UDR1 = data;
}

//USART0 RX
unsigned char USART1_Receive( void )
{
while (!(UCSR1A & (1 << RXC1)) ); // Do nothing until data have been recieved and is ready to be read from UDR
return (UDR1); // return the byte
  
}

// buffer transmission through 1st UART
void usart0_transmission(cBuffer* );

// add a string to buffer
void addtobuffer(cBuffer*, char* );

// function I used 1st to send sms
void send_string(char*);

// variables for buffer initializatuon
#define USART0_BUFFER_SIZE 0x080
static unsigned char usart0_buffer_addr[USART0_BUFFER_SIZE];

cBuffer* usart0_buffer,usart1_buffer;

int main()
{

// AT commands for sms
char *CMGF = "AT+CMGF=1\r";
char *CMGS = "AT+CMGS=\"9673408606\"\r";
char *MSG = "This is a test message.\r";
char *CTRLZ = "\x1a\r";


DDRA = 0xFF;
PORTA = 0xFF;

USART0_Init();//9600 buad rate
USART1_Init();//9600 baud

bufferInit(usart0_buffer, usart0_buffer_addr, USART0_BUFFER_SIZE);
//bufferInit(usart1_buffer, (unsigned char*)usart1_buffer, 100);

/* procedure used for transmitting string through uart */
/*
//while( USART0_Receive() );
send_string(CMGF);
_delay_ms(100);

//while( USART0_Receive() );
send_string(CMGS);
_delay_ms(100);

//while( USART0_Receive() );
send_string(MSG);
_delay_ms(100);

//while( USART0_Receive() );
send_string(CTRLZ);
_delay_ms(100);
*/

// new procedure used for transmission
bufferFlush(usart0_buffer);
addtobuffer( usart0_buffer, CMGF );
addtobuffer( usart0_buffer, CMGS );
addtobuffer( usart0_buffer, MSG );
addtobuffer( usart0_buffer, CTRLZ );


usart0_transmission(usart0_buffer);

return 0;
}


void send_string(char* data)
{
	int i = 0;
	while(i < strlen(data))
	{
		//UDR0 = 0;
		USART0_Transmit(data[i]);
		_delay_ms(100);
		i++;
	}
}


void usart0_transmission(cBuffer* buffer)
{

	int i=0;

	while(i < buffer->size)
	{
		unsigned char data = '0';
		data = bufferGetFromFront(buffer);
		USART0_Transmit(data);	
		//PORTA = data;
		i++;
	}

}


void addtobuffer(cBuffer* buffer, char* data)
{
	int i=0;
	while(i < strlen(data))
	{
		bufferAddToEnd(buffer,data[i]);
		i++;
	}
}

my build output

Build started 4.3.2013 at 19:21:03
avr-gcc -I"C:\Users\Nikhil\Documents\AVR\sms\..\libr"  -mmcu=atmega162 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT sms.o -MF dep/sms.o.d  -c  ../sms.c
avr-gcc -mmcu=atmega162 -Wl,-Map=sms.map sms.o   -L"C:\Users\Nikhil\Documents\AVR\libr"  -lr  -o sms.elf
avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature  sms.elf sms.hex
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ihex sms.elf sms.eep || exit 0
avr-objdump -h -S sms.elf > sms.lss
Build succeeded with 0 Warnings...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What's the point in using buffers when your are operating synchronously?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually I made this program to debug buffers.. as I am using procyon's nmea parser library in my other code.. that code too was not working even though it had no errors but some datatype signedness warnings