Sign in

username:

password:



Not a member?

Search avrclub



Search tips

Subscribe to avrclub



avrclub by Keywords

AT90S2313 | AT90S8515 | ATMega | ATmega128 | ECL | FETS | IAR | Keyboard | LCD | STK50 | TMOS | UART

Ads

Discussion Groups

Discussion Groups | AVRclub | [AVR club] An 'strange' synchronization lost problem in USART!

Atmel AVR Microcontroller discussion group.

[AVR club] An 'strange' synchronization lost problem in USART! - Rakesh Kumar - Jul 1 3:25:49 2007

Hello All,

Atmega32 clocked at 11.0592 MHz.
Using ADC for taking samples at a prescaler of 64.
USART communication at 9600 bps.

Here's the thing, I have written two codes in AVR-GCC, both using the same
initialization settings and routines . One of them is transmitting data
properly through an XBEE RF module chip interfaced to a computer.

Other is just filling out dots. (Loss of sync I guess)

Following are the codes. Give out any insights you might have.

Thanks...

-----------------------
Code Working Properly
-----------------------
InitSerial();
adc_init();
int machine_counter=0;
int dummy;
int j;

while (1)
{
int max_a=0; int b_a_max; int t_max_a;

int min_a=1023; int b_a_min; int t_min_a;

int max_b=0; int a_b_max; int t_max_b;

int min_b=1023; int a_b_min; int t_min_b;

TransmitString("Hello, Here it goes:",20);

for (j=0; j<100; j++)
{
int sensor_a=readadchan(0);
int sensor_b=readadchan(1);

if (sensor_a > max_a)
{
max_a=sensor_a;
b_a_max=sensor_b;
t_max_a = machine_counter;
}

if (sensor_a < min_a)
{
min_a=sensor_a;
b_a_min=sensor_b;
t_min_a = machine_counter;
}

if (sensor_b > max_b)
{
max_b=sensor_b;
a_b_max=sensor_a;
t_max_b = machine_counter;
}

if (sensor_b < min_b)
{
min_b=sensor_b;
a_b_min=sensor_a;
t_min_b = machine_counter;
}

machine_counter++;
}

/*dummy = max_a & 0xFF;
max_a = max_a >> 8;

TransmitString(" MAX A:",7);
TransmitByte(max_a);
TransmitByte(dummy);

dummy = b_a_max & 0xFF;
b_a_max = b_a_max >> 8;

TransmitString(" B A MAX:",9);
TransmitByte(b_a_max);
TransmitByte(dummy);

TransmitString(" Count at MAX A:",16);
TransmitByte(t_max_a);

dummy = min_a & 0xFF;
min_a = min_a >> 8;

TransmitString(" MIN A:",7);
TransmitByte(min_a);
TransmitByte(dummy);

dummy = b_a_min & 0xFF;
b_a_min = b_a_min >> 8;

TransmitString(" B A MIN:",9);
TransmitByte(b_a_min);
TransmitByte(dummy);

TransmitString(" Count at MIN A:",16);
TransmitByte(t_min_a);
dummy = max_a & 0xFF;
max_a = max_a >> 8;

TransmitString(" MAX B:",7);
TransmitByte(max_b);
TransmitByte(dummy);

dummy = a_b_max & 0xFF;
a_b_max = a_b_max >> 8;

TransmitString(" A B MAX:",9);
TransmitByte(a_b_max);
TransmitByte(dummy);

TransmitString(" Count at MAX B:",16);
TransmitByte(t_max_b);

dummy = min_b & 0xFF;
min_b = min_b >> 8;

TransmitString(" MIN B:",7);
TransmitByte(min_b);
TransmitByte(dummy);

dummy = a_b_min & 0xFF;
a_b_min = a_b_min >> 8;

TransmitString(" A B MIN:",9);
TransmitByte(a_b_min);
TransmitByte(dummy);

TransmitString(" Count at MIN B:",16);
TransmitByte(t_min_b);

*/

TransmitString(" MAX A:",7);
TransmitInt(max_a);

TransmitString(" B A MAX:",9);
TransmitInt(b_a_max);

TransmitString(" Count at MAX A:",16);
TransmitInt(t_max_a);

TransmitString(" MIN A:",7);
TransmitInt(min_a);

TransmitString(" B A MIN:",9);
TransmitInt(b_a_min);

TransmitString(" Count at MIN A:",16);
TransmitInt(t_min_a);

TransmitString(" MAX B:",7);
TransmitInt(max_b);

TransmitString(" A B MAX:",9);
TransmitInt(a_b_max);

TransmitString(" Count at MAX B:",16);
TransmitInt(t_max_b);

TransmitString(" MIN B:",7);
TransmitInt(min_b);

TransmitString(" A B MIN:",9);
TransmitInt(a_b_min);

TransmitString(" Count at MIN B:",16);
TransmitInt(t_min_b);

machine_counter=0;

}
return 0;

----------------
Code Not working
----------------

int main (void)
{
InitSerial();
adc_init();
int sensor_a;
int sensor_b;
while (1)
{
sensor_a=readadchan(0);
TransmitInt(sensor_a);

sensor_b=readadchan(1);
TransmitInt(sensor_b);

}
return 0;
}

--
Rakesh.
http://gopchandani.wordpress.com
[Non-text portions of this message have been removed]


(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )