Help with atmega1284

Hi,

this is regarding atmega1284.

Hi,

i am working with Atmega1284. and prblem is with C library.

I am using Pololu library, which is actually writtten for there own product but i think that it should also work with some other atmega1284 setup.

Problem is i am not able to do the usart communication using pololu library.

trying on the other way, tried to write my own code for serial communication on usart, transmitter code done fine, but receive code not working and goes all time for waiting state to receive data.

unsigned char receiveFromUsart(int usartPortNum){
	unsigned char recData;
	
	switch( usartPortNum )  {
		case 0:
			while( !(UCSR0A & (1<<RXC0))){
				blinkLed();
			}
			recData = UDR0;	
			return recData;
			
			
		break;
		case 1:
			while( !(UCSR1A & (1<<RXC1))){
				blinkLed();
			}
			PORTC &= (0<<INDICATE_LED);
			recData =  UDR1;
			return recData;
		break;
	}
}

Please ignore the blinkLed routine call for now, as i put that to monitor the execution point.

My receive code for now.
Please take a look, where i am going wrong with this.

  • Is there any other library for atmega1284 ← (“1284”).

Thank you.

Try the mighty1284 core set

Board type “Bobuino” sets up the pinouts I use on my Arduino-styled 1284P based cards.
http://www.crossroadsfencing.com/BobuinoRev17/

Please take a look on my usart api so written -

Code:

void blinkLed(){ 
   PORTC |= (1<<INDICATE_LED); 
   _delay_ms(50); 
   PORTC ^= (1<<INDICATE_LED); 
   _delay_ms(50); 
} 
void usartInit(unsigned char chBaudRate, int uartNum ){ 
   //12MHz, 77 
   switch( uartNum ){ 
      case 0: 
      UBRR0H = (unsigned char)(chBaudRate>>8); 
      UBRR0L = (unsigned char)(chBaudRate); 
       
      //enable rx and tx 0. 
      UCSR0B = (1<<RXEN0)|(1<<TXEN0); 
       
      //set frame and stop bit configuration 
      UCSR0C = (0<<USBS0)|(3<<UCSZ00); 
      break; 
      case 1: 
      UBRR1H = (unsigned char)(chBaudRate>>8); 
      UBRR1L = (unsigned char)(chBaudRate); 
       
      //enable rx and tx 0. 
      UCSR1B = (1<<RXEN1)|(1<<TXEN1); 
       
      //set frame and stop bit configuration 
      UCSR1C = (0<<USBS1)|(3<<UCSZ10); 
      break; 
   }    
} 



void sendFromUsart( unsigned char data, int uartPort){ 
   //wait for empty transmitter buffer. 
   switch( uartPort ){ 
      case 0: 
      while( !(UCSR0A&(1<<UDRE0)) ); 
      UDR0 = data; 
      break; 
      case 1: 
      while( !(UCSR1A&(1<<UDRE1)) ); 
      UDR1 = data; 
      break; 
   } 
    
} 

void sendStringFromUsart(unsigned char *str, int uartPortNum){    
   while( *str ) 
   sendFromUsart( *str++, uartPortNum); 
} 

unsigned char* receiveFromUsart(int usartPortNum){ 
   unsigned char recData; 
       
   switch( usartPortNum )  { 
      case 0: 
         while( !(UCSR0A & (1<<RXC0))){ 
            blinkLed(); 
         } 
         return (unsigned char)UDR0; 
      break; 
      case 1: 
         while( !(UCSR1A & (1<<RXC1))){ 
            blinkLed(); 
         } 
         return (unsigned char)UDR1; 
      break; 
   } 
}

Then i changed my code and also incorporated the ISR for RXT on N port,
So please take a look again for next version of code below.

void usartInit(unsigned char chBaudRate, int uartNum ){
	//12MHz, 77
	switch( uartNum ){
		case 0:
		UBRR0H = (unsigned char)(chBaudRate>>8);
		UBRR0L = (unsigned char)(chBaudRate);
		
		//enable rx and tx 0.
		UCSR0B = (1<<RXEN0)|(1<<TXEN0);
		
		//set frame and stop bit configuration
		UCSR0C = (0<<USBS0)|(3<<UCSZ00);
		//
		break;
		case 1:
		UBRR1H = (unsigned char)(chBaudRate>>8);
		UBRR1L = (unsigned char)(chBaudRate);
		
		//enable rx and tx 0.
		UCSR1B = (1<<RXEN1)|(1<<TXEN1);
		
		//set frame and stop bit configuration
		UCSR1C = (0<<USBS1)|(3<<UCSZ10);
		//
		break;
	}	
}
void sendFromUsart( unsigned char data, int uartPort){
	//wait for empty transmitter buffer.
	switch( uartPort ){
		case 0:
		while( !(UCSR0A&(1<<UDRE0)) );
		UDR0 = data;
		break;
		case 1:
		while( !(UCSR1A&(1<<UDRE1)) );
		UDR1 = data;
		break;
	}
	
}
void usartEableRecieveInt(int nPortNum){
	switch( nPortNum ){
		case 0:
			//enable the rx of usart 0 interrupt.
			UCSR0B |= (1<<RXCIE0);
		break;
		case 1:
		//enable the rx of usart 1 interrupt.
			UCSR1B |= (1<<RXCIE1);
		break;
	}
}
void sendStringFromUsart(unsigned char *str, int uartPortNum){	
	while( *str )
	sendFromUsart( *str++, uartPortNum);
}
unsigned char receiveFromUsart(int usartPortNum){
	unsigned char recData;		
	switch( usartPortNum )  {
		case 0:
			while( !(UCSR0A & (1<<RXC0))){
				//blinkLed();
			}
			recData = UDR0;
			return recData;
		break;
		case 1:
			while( !(UCSR1A & (1<<RXC1))){
				//blinkLed();
			}
			recData = UDR1;
			return recData;
		break;
	}
}
void receivedDataNow( unsigned char chData, int nPortFrom){
	
	toggle();
	switch( nPortFrom ){
		case 0:
			//////////////////////////////////////////////////////////////////////////
			// received data rom usart 0.
			// action code goes here
		break;
		case 1:
			//////////////////////////////////////////////////////////////////////////
			// received data from usart 1.
			// action ccode goes here
			sendFromUsart(chData, 0);
		break;
	}
}	
ISR(USART1_RX_vect){ // Here USART1_RX_vect is defined in headerfile at VECTOR # 28.
// But in atmega1284 datasheet it is defined at VECTOR 29.
//How do i redefine it?
	unsigned char chRecvData;
	chRecvData = UDR1;
	receivedDataNow(chRecvData, 1);
}

So, i have enabled RXENn and that Receive transmission is working when i connect atmega1284 with computer, i can read on RealTerm window with 9600 br.

problem is,

  • i am working with sim900 + atmega1284.
    now i can send command to sim 900 and it responds wweill, but unable to catch the response from sim900 as RX.

  • Aim is to catch the response from sim900 and do some verify-kinda actions.

  • And i will remove the blnkLed() to be more immediate to catch response from sim900.

  • In code

  • Here USART1_RX_vect is defined in headerfile at VECTOR # 28.

  • But in atmega1284 datasheet it is defined at VECTOR 29.

For now i am not going with bobuino board. Please help me with getting this correct. Or any library apart from bobuino and pololu, do let me know.

Added: You may also find some answers to serial issues in the Pololu write-up on serial comms here: http://www.pololu.com/docs/0J18/10

For now i am not going with bobuino board. Please help me with getting this correct. Or any library apart from bobuino and pololu, do let me know.

Maniac's library had nothing to do with the Bobduino boards.txt file. Maniacbug library is the 'core' library for the 1284 which has a good reputation for working. I have used it with FFT and several other sketches and it functions well.

You can build your own boards.txt file and call your board Banerjee if you like. Here is the Goldilocks file for 20MHz :

# See: http://code.google.com/p/arduino/wiki/Platforms
# This file already has the added references for Goldilocks
##############################################################

goldilocks_20MHz.name=Goldilocks @ 20MHz

goldilocks_20MHz.upload.protocol=wiring
goldilocks_20MHz.upload.maximum_size=122878
goldilocks_20MHz.upload.speed=38400

goldilocks_20MHz.bootloader.low_fuses=0xd7
goldilocks_20MHz.bootloader.high_fuses=0xd8
goldilocks_20MHz.bootloader.extended_fuses=0xfc
goldilocks_20MHz.bootloader.path=stk500v2
goldilocks_20MHz.bootloader.file=stk500boot_v2_goldilocks.hex
goldilocks_20MHz.bootloader.unlock_bits=0x3F
goldilocks_20MHz.bootloader.lock_bits=0x0F

goldilocks_20MHz.build.mcu=atmega1284p
goldilocks_20MHz.build.f_cpu=20000000L
goldilocks_20MHz.build.core=arduino
goldilocks_20MHz.build.variant=goldilocks

In the above, the core files are referenced back to Arduino but the variant files are referenced to the sub-directory variants\goldilocks When configured this way, the variant folder contains the pins_arduino.h file used to remap the physical pins to the logical Arduino variety.

Boarduino takes a different approach and replaces the Arduino core files with its own set.

********************************************************************
bobuino.name=Bobuino
bobuino.upload.protocol=arduino
bobuino.upload.maximum_size=130048
bobuino.upload.speed=115200
bobuino.bootloader.low_fuses=0xff
bobuino.bootloader.high_fuses=0xde
bobuino.bootloader.extended_fuses=0xfd
bobuino.bootloader.path=optiboot
bobuino.bootloader.file=optiboot_atmega1284p.hex
bobuino.bootloader.unlock_bits=0x3F
bobuino.bootloader.lock_bits=0x0F
bobuino.build.mcu=atmega1284p
bobuino.build.f_cpu=16000000L
bobuino.build.core=standard
bobuino.build.variant=bobuino

********************************************************************

Examination also shows that the fuses are different because the uC core runs at 20MHz with Goldilocks and at 16MHz with Boarduino.

I have used the Boarduino successfully. I do not think your issue is with the Pololu library, but it would not hurt to try and recompile using Boarduino to see if you have any different results... it rules out any concern in this area.

Ray

I'm a little curious of why you are using 'low level' register control to access one of the internal uart of the 1284p? The arduino Serial library supports Serial and Serial1 for the 1284p library access as it also does support all four internal hardware uarts in the mega 1280/2560.

Lefty

void usartInit(unsigned char chBaudRate, int uartNum ){ : UBRR0H = (unsigned char)(chBaudRate>>8); UBRR0L = (unsigned char)(chBaudRate);

If "chBaudRate" is an unsigned char, then this initialization is not correct. (actually, it probably works for most common baud rates, but...) How are you calling usartInit() ? (those don't look like the Pololu functions that I can find documentation for...)

ah,

finalyy, i just pulled all pololu lib files and build with my project, now serial transmission is working fine with pololu. But my problem remains the same.

That problem was with usart receive data. Transmission code is working good.