Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
barjaktar
PostPosted: Apr 09, 2012 - 06:15 PM
Rookie


Joined: Apr 20, 2011
Posts: 40


Hello.

I am trying to use ATmega1281 within the ATZB-24-A2 module. I have been programming it using the Serial Bootloader application through the serial connection from my PC. I use WinAVR to create an .elf file, and then the avr-objcopy.exe to create .srec file.

I am having problems with UART set-up for my 1281. From schematic of ATZB-24-A2 (given by alexru, at: http://dl.dropbox.com/u/6121480/ATZB_24_A2_sch.jpg), I see that UART pins of ATZB-24-A2 are actually USART1 pins of 1281.

Thus, 1281 USART1 configuration is as follows:

Code:
void USART_I(uint16_t ubrr_value)
{
    UBRR1H = (unsigned char)(ubrr_value>>8);
    UBRR1L = (unsigned char)ubrr_value;

    UCSR1C = (1<<UCSZ10)|(1<<UCSZ11); //asynchronous
    UCSR1B = (1<<RXEN1)|(1<<TXEN1);
}

char USART_R(void)
{
   while(!(UCSR1A & (1<<RXC1)));
   
   return UDR1;
}

void USART_W(unsigned char data)
{
   while(!(UCSR1A & (1<<UDRE1)));

   UDR1 = data;
}


After reading about ATZB-24-A2, I see that it works at 1MHz. Namely, it's internal oscillator gives 8MHz, but it's prescaler bit is set, so it divides frequency by 8, thus 1MHz. This is fine for me, so I leave it at that.

My application is just to test UART connection, so:

Code:
int main(void)
{
   USART_I(1);//BAUD = 38400 at 1MHz
   
   while(1)
   {
      USART_W(0xFA);
      _delay_ms(500);
   }
   
   return 0;
}


Setting up my RealTerm to work at 38400, it recieves:

Code:
0x00 0xFF 0xFA 0xFA 0xFA 0xFA 0x00 0xFF 0xFA 0xFA 0xFA 0xFA and so on...


I figured that these errors come from a high error rate for baud = 38400 at 1MHz (18.6%, pp. 227, 1281 datasheet), so I went down to baud = 2400. Thus, I lowered the error rate to 0.2%, but what comes out does not differ a lot (now it's USART_I(25)):

Code:
0x00 0xFA 0xFA 0xFA 0xFA 0xFA 0xFA 0xFA 0xFA 0xFA 0xFA 0xFA 0xFA 0x00 0xFA and so on...


It seems to me like quite a lot of errors - every 13th byte is wrong...

Could you, please, advise me where to look for misconfiguration? What did I do wrong that could create so many errors in communication?

Did I correctly understand the frequency configuration of ATZB-24-A2? Is it somehow supposed to work at baud = 38400 (since it's default baud rate at which the Bootloader uploads the .srec image...)?

Used makefile is attached (as .txt).

Thank you.
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Apr 09, 2012 - 08:49 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

Bootloader will calibrate RC oscillator to a frequency = 921600 Hz (38400*24). There are two versions of bootloader, one will leave calibration bytes as is (tuned to 921600 Hz) and expect HAL to calibrate again (and BitCloud HAL does it), another will save existing bytes and then return them back after bootloader finished.

It is hard to tell which version you are using, but I see 2 possible options:
1. First version and frequency is off, but that would mean that your 38400 experiment should work.
2. Second version and your calibration is off from the beginning.

In any case I would perform calibration at the start of your program. See file \BitCloud\Components\HAL\avr\atmega1281\common\src\calibration.c from the original SDK for reference.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
barjaktar
PostPosted: Apr 10, 2012 - 12:12 PM
Rookie


Joined: Apr 20, 2011
Posts: 40


Thank you.

Bootloader version is 1.2.1.

I changed UART set up for 921600Hz. Thus:

Code:
UBRR = [921600 / (8 * 38400)] - 1 = 2
//U2X = 1 => 8 in the divider;


Still, I get the same - those zeros keep popping up.

But, I did another experiment. Somewhere (on this forum, I think) I read that somebody noticed that his module kept reseting on its own. So I created the following srec image:

Code:
int main(void)
{
   USART_I(2);//BAUD = 38400, double speed
   
   char i = 0x00;
   
   while(1)
   {
      USART_W(i);
      _delay_ms(500);
      i++;
   }
   
   return 0;
}


The output was quite interesting:

Code:
0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x00 0xFE 0x00 0x01 0x02 ... and so on ...


This looks to me like it really keeps reseting itself... So, the zeros aren't the result of the error, but of a reset.

This guy said that he figured out to solve his problem by disabling watchdog timer. So I added the following lines to my code:
Code:

   WDTCSR = 0x00;
   MCUSR = 0x00;


But... still the same thing. It counts up to seven and (probably) restarts itself.

I am not able to change the fuse bits, since I only have serial connection as an option for progamming.

Does the "restart story" make sense? How should I stop it?

Thank you.
 
 View user's profile Send private message  
Reply with quote Back to top
barjaktar
PostPosted: Apr 10, 2012 - 01:54 PM
Rookie


Joined: Apr 20, 2011
Posts: 40


Yep, definetly, it is a watchdog reset.

MCUSR says it is so - at start up, it is always 0x08, which means WDRF = 1.

So I clear MCUSR, and then I clear WDTCSR:

Code:

/* in order to be able to clear WDE, WDRF must be cleared first */
MCUSR = 0x00;
/* WDIF (bit 7 of WDTCSR) is cleared by writing 1;
   WDIE (bit 6) is cleared => watchdog disabled;
   to clear WDE, WDCE (bit 4) must be set;
   WDE (bit 3) is cleared;
   prescaler bits (5, 2, 1, 0) are cleared;*/
WDTCSR = 0x90;


This should be enough, since the datasheet claims (page 68 ) that the watchdog timer should be stopped if WDE and WDIE are cleared and WDTON is set.

Still, the reset happens all the time. Why?
 
 View user's profile Send private message  
Reply with quote Back to top
barjaktar
PostPosted: Apr 10, 2012 - 02:11 PM
Rookie


Joined: Apr 20, 2011
Posts: 40


Ok, I figured it out.

There is an actual sequence when writing bits into WDTCRS register (datasheet, page 65). With this I was able to disable watchdog timer.

Now my UART example works perfect. The topic can be considered SOLVED.

It looks like as if this bootloader version is the one that sets the frequancy at 921600Hz.

Thank you, alexru.
 
 View user's profile Send private message  
Reply with quote Back to top
Edgar_Noel2
PostPosted: May 30, 2012 - 01:57 PM
Newbie


Joined: May 30, 2012
Posts: 6


Hello.

I can not use the bootloader for ATZB-24-A2 module,
the bootloader version is 1.2.1, the download never begins only apper the message please restart device.

I tried to reset the module with the pin 8 to low (reset pin) but the download does not begin.

I am using a FTDI module as bridge USB-RS232

*I attached the schematic that I am using

Thanks
 
 View user's profile Send private message  
Reply with quote Back to top
Edgar_Noel2
PostPosted: May 30, 2012 - 01:59 PM
Newbie


Joined: May 30, 2012
Posts: 6


Hello.

I can not use the bootloader for ATZB-24-A2 module,
the bootloader version is 1.2.1, the download never begins only apper the message please restart device.

I tried to reset the module with the pin 8 to low (reset pin) but the download does not begin.

I am using a FTDI module as bridge USB-RS232

*I attached the schematic that I am using

Thanks
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: May 30, 2012 - 05:01 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

To what pins of FTDI you have connected RXD and TXD pins?

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
Edgar_Noel2
PostPosted: Jun 05, 2012 - 02:15 AM
Newbie


Joined: May 30, 2012
Posts: 6


Sorry.. this image corresponds about the module used in the end device.
Those lines in the board that uses the FTDI are connected
RXD_FTDI-RXD and TXD_FTDI-TXD
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Jun 05, 2012 - 02:28 AM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

You need to switch them like this: RXD_FTDI-TXD and TXD_FTDI-RXD. ZigBit is a modem device, so TXD is "data to transmit" and RXD id "received data".

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
Edgar_Noel2
PostPosted: Jun 05, 2012 - 02:36 AM
Newbie


Joined: May 30, 2012
Posts: 6


BTW... cause I cannot progam the modules via bootloader.
I decided to load the firmware via JTAG(dragon device) using AVR Studio I load SerialNet_ZigBit_Rf230.hex and everything seems ok but when I try to test the command ATX I do not receive a OK answer... I think that it could be a baud rate problem... where can I look the correct fuse configuration??

Thanks
 
 View user's profile Send private message  
Reply with quote Back to top
uracolix
PostPosted: Jun 05, 2012 - 07:12 AM
Hangaround


Joined: Jun 17, 2008
Posts: 454
Location: Meissen, Germany

When I looked in my first ZigBits, I found:

LF: 0x62
HF: 0x1d
EF: 0xff

I hope that this are the original settings.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
Edgar_Noel2
PostPosted: Jun 05, 2012 - 01:21 PM
Newbie


Joined: May 30, 2012
Posts: 6


Does the AVR MCU may be damaged if I configure wrong these values??
I changed some values and now a message that says error in configuration bits is showed and I cannot program it again.
Is possible to fix It?
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Jun 05, 2012 - 04:51 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

Yes, if you select incorrect clock source then device will lock up. How bad it is depends on what you have set.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
Edgar_Noel2
PostPosted: Jun 05, 2012 - 08:25 PM
Newbie


Joined: May 30, 2012
Posts: 6


Ok, I think that I damaged it.
But I have two modules, What is the correct fuse configuration? I don´t want to damage the last one that I have.

After download SerialNet.hex, what baud rate do I shall use to implement the AT commands? (I´m not sure if 38400bps is ok)

Now I have the conections as you told me yesterday (RXD_FTDI-TXD and TXD_FTDI-RXD)

Thank you for your answer I am overdue and your help will be so usefull to me.
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Jun 05, 2012 - 08:45 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

Correct fuse configuration should be mentioned in the datasheet. But I think you don't need to change any of them, just program SerialNet.srec (or .hex, depending on the method). 38400 8N1 should work.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
matwil3
PostPosted: Jun 21, 2012 - 02:09 AM
Newbie


Joined: Jun 21, 2012
Posts: 12


Hi.

I have a problem with communication using AT commands in ATZB-24-A2. Programming the module seems to be ok, I can program it by bootloader (SerialNet_ZigBit_Rf230.srec) and it returns 'Upload Complete' and also by AVR programmer STK500 (SerialNet_ZigBit_Rf230.hex). In both methods there aren't any errors. Problem appears when I try to test the module in Terminal. When I send to the ATZB 'at', 'ati' or any other AT command I receive exactly the same what I sent (send 'at', receive 'at').

I use FTDI converter (USB-RS232), parameters: 38400, 8 data bits, 1 stop bit, no parity and no handshaking. I have no idea what else can I do. Maybe someone's had the same problem. Advise me something, please.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
alexru
PostPosted: Jun 21, 2012 - 02:55 AM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

Do you expect more data and it does not arrive? Because SerialNet will echo entered characters by default and then it will send response.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
matwil3
PostPosted: Jun 21, 2012 - 08:51 AM
Newbie


Joined: Jun 21, 2012
Posts: 12


Thanks for response. I wait always a moment after I send 'at'. But I get immediatelly echo and than nothing more. Without SerialNet the module doesn't respond anything, what is obvious.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
matwil3
PostPosted: Jun 21, 2012 - 11:57 PM
Newbie


Joined: Jun 21, 2012
Posts: 12


I'd like to make sure I'm right - when I'll program ATZB by SerialNet_ZigBit_Rf230.srec I am able to use AT command without any other configuration of the module? I'm using just UART_RXD, UART_TXD and of course 2 VCCs and 4 GNDs. RESET is unconnected but it behaves as it is connected to logical 1 (I mean, it does not affect operation of the module).

And one more thing you mentioned, how much time this module need for response after echo appears? I guess it should be quite fast.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
alexru
PostPosted: Jun 21, 2012 - 11:59 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

It should be few ms.

Can you try it from HyperTerminal or similar program?

I don't really know why it behaves like this.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
matwil3
PostPosted: Jun 22, 2012 - 12:37 AM
Newbie


Joined: Jun 21, 2012
Posts: 12


Yes, exactly it's terminal from here: https://sites.google.com/site/terminalbpp/

Weird thing is I tested two ATZB modules and both behave the same.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
alexru
PostPosted: Jun 22, 2012 - 12:55 AM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

May be you have local echo enabled and module does not receive anything?

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
matwil3
PostPosted: Jun 22, 2012 - 01:04 AM
Newbie


Joined: Jun 21, 2012
Posts: 12


How can I check or change it? Is it in configuration of the module or you mean TXD and RXD are connected together somewhere?
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
alexru
PostPosted: Jun 22, 2012 - 01:05 AM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

No, module should work fine as is. You can't configure it without getting access first anyway. It should be in the configuration of the terminal program.

BTW, do you see the same characters if you disconnect the module?

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
matwil3
PostPosted: Jun 22, 2012 - 01:12 AM
Newbie


Joined: Jun 21, 2012
Posts: 12


No, when module is disconnected there is nothing in receive window. And it's the same when module is connected to FTDI converter but there isn't SerialNet programmed.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
alexru
PostPosted: Jun 22, 2012 - 01:16 AM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

Do you press <Enter>? Try different settings for End Of Line character, like CR, LF and CR+LF.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
matwil3
PostPosted: Jun 22, 2012 - 01:32 AM
Newbie


Joined: Jun 21, 2012
Posts: 12


You are the best Wink So small detail... But in this terminal is written that after pressing <ENTER> there is inserted CR character in the end of sending expression, but it wasn't work. When I send 'AT#013' everything works great. Thanks a lot for help.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
matwil3
PostPosted: Jun 23, 2012 - 03:39 PM
Newbie


Joined: Jun 21, 2012
Posts: 12


I've just remembered one more question. Do you know what is the approximate range of ATZB-24-A2? I've looked for this information in the datasheet and some forums but without success.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
alexru
PostPosted: Jun 23, 2012 - 06:16 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

That depends on how you design your board. You can expect anything from 5 to 50 meters. Sometimes even more, but not really reliable and not in all antenna orientations.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
matwil3
PostPosted: Jun 23, 2012 - 10:32 PM
Newbie


Joined: Jun 21, 2012
Posts: 12


I thought so. Ok, thank you very much.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
matwil3
PostPosted: Sep 26, 2012 - 08:48 PM
Newbie


Joined: Jun 21, 2012
Posts: 12


Hi again.

I have a question about PCB for ATZB-24-A2. My PCB is filled by ground, even in area occupied by the module. I wonder it may influence on the range of the module. Or maybe you have some other tips how can I increase the range?
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
alexru
PostPosted: Sep 26, 2012 - 08:55 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4861
Location: San Jose, CA

There should not be ground plane under the antenna part of the module. That will affect the range (technically you are just shielding the antenna).

Ground plane under the module itself is not recommended, but acceptable.

Generally antenna on ATZB-24-A2 gives better performance if if is located flush with the PCB side (not hanging over from the PCB).

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
matwil3
PostPosted: Sep 26, 2012 - 10:17 PM
Newbie


Joined: Jun 21, 2012
Posts: 12


OK, I'll change it. Thanks.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
matwil3
PostPosted: Oct 02, 2012 - 02:38 PM
Newbie


Joined: Jun 21, 2012
Posts: 12


It helped a lot. The range is much bigger now. Thanks again Wink
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits