Solved: Serial speed way over 115.200!

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

I will need some help on this.
 

I tried for several hours but I do not know where else to look. Some time ago I was interfacing a GPS module with an ATmega164p and everything was just fine. I could get the NMEA string in and I could send text over the serial port out. So I had to work in another project and now, several months later, I´m back on this. Checking if everything was ok, I realize I could not get NMEA strings anymore and neither send strings over the serial. I Checked everything I could remember and all looks fine. So I hook the scope probe to GPS serial output and everything is fine at 9600. But checking the serial TX output from micro controller I noted that the speed is way over 400.000 baud! How can it be possible? I´m using a 4MHz xtal. My baud is set to 9600 (25). For this speed a bit width should be 104.17us, but I´m getting 2us. 

Anyone have any idea where to look?

Here some pieces of the serial code settings and the fuses (image):

	int baud = 25;	// 25=9600
	
	UBRR0H = (unsigned char) (baud >> 8);	// define baud
	UBRR0L = (unsigned char) baud;
	UCSR0B = (1<<TXEN0) | (1<<RXEN0);		// set TX RX
	UCSR0C = (1<<UCSZ00)|(1<<UCSZ01);		// 8 bits
	UCSR0B |= (1 << RXCIE0);
	
	UBRR1H = (unsigned char) (baud >> 8);	// define baud
	UBRR1L = (unsigned char) baud;
	UCSR1B = (1<<TXEN1) | (1<<RXEN1);		// set TX RX
	UCSR1C = (1<<UCSZ10)|(1<<UCSZ11);		// 8 bit
	UCSR1B |= (1 << RXCIE1);

 

Attachment(s): 

This topic has a solution.

Good Soldering JRGandara

Last Edited: Sat. May 23, 2015 - 02:40 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have enabled the receive interrupts for each USART.  Have you provided an ISR for each?  If not, then your code will reset as soon as a character is received.  If so, then post the code.

 

Post the smallest complete program which demonstrates the problem.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#include <stdio.h>
#include <avr/interrupt.h>
#define F_CPU 4000000UL
#include <util/delay.h>
#include <string.h>
#include <stdbool.h>												// needs for boolean
#include <sbit.h>
#include <math.h>

#define LED_ON PORTA |= (1<<PA4)
#define LED_OFF PORTA &= ~(1<<PA4)
#define POWERKEY_HIGH PORTB |= (1<<PB1)
#define POWERKEY_LOW PORTB &= ~(1<<PB1)
#define DTR_ON PORTB |= (1<<PB3)
#define DTR_OFF PORTB &= ~(1<<PB3)

uint8_t flag_usart_rx;
int baud = 25;					// 25=9600

uint8_t TX_SERIAL_GSM (char data)
{
	/* Wait for empty transmit buffer */
	while ( !( UCSR0A & (1<<UDRE0)) );
	/* Put data into buffer, sends the data */
	UDR0 = data;
	return (0);
}


int main(void)
{
	
	DDRA=0b00010001;		//PA0=LED
	PORTA=0b00000000;
	DDRB=0b00001010;
	PORTB=0b00000010;
	DDRD=0b00000000;		//PA0=LED
	PORTD=0b00000000;
	

	UBRR0H = (unsigned char) (baud >> 8);	// define baud GSM
	UBRR0L = (unsigned char) baud;
	UCSR0B = (1<<TXEN0) | (1<<RXEN0);		// seta TX RX
	UCSR0C = (1<<UCSZ00)|(1<<UCSZ01);		// 8 bits
	UCSR0B |= (1 << RXCIE0);
	
	UBRR1H = (unsigned char) (baud >> 8);	// define baud GPS
	UBRR1L = (unsigned char) baud;
	UCSR1B = (1<<TXEN1) | (1<<RXEN1);		// seta TX RX
	UCSR1C = (1<<UCSZ10)|(1<<UCSZ11);		// 8 bit
	UCSR1B |= (1 << RXCIE1);

	sei();
	prt_serial=0;

	LED_ON;
//	_delay_ms(3000);
//	POWERKEY_LOW;							//Power key pulse 1s low to turn on
//	_delay_ms(1000);
//	POWERKEY_HIGH;
//	_delay_ms(1000);
//	TX_SERIAL_GSM('A');
	
	while(1)
    {
	
	TX_SERIAL_GSM('A');
    }
}

ISR (USART1_RX_vect)
{
	uart_getchar = UDR1 ; // Fetch the received byte value into the variable " ByteReceived "
	flag_usart_rx=1;
}

I can see in the scope the letter A being transmitted, but at non standard speed. 

Good Soldering JRGandara

Last Edited: Thu. May 21, 2015 - 02:42 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That is not a "complete program".  It couldn't possibly compile.

 

You have:

  prt_serial=0;

... but there is no definition for prt_serial.

 

You are still enabling RXCIE0 without providing an ISR for USART0_RX_vect.

 

Please copy/paste the actual program you have which is actually demonstrating the actual problem.  If one thing is missing, what's to say there isn't something else missing?   Perhaps one of the other missing parts is responsible for the problem.  Nobody likes to chase down ghosts ;)

 

Also post the .lss of the actual program.

 

Have you confirmed that your AVR is running at 4MHz?  How?

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

Here is the complete code. I keep only code for USART0 which is the one I´m using. There is no more code than this because it is only a serial 1 test. 

 

/*
 * STS500.c
 *
 * Created: 24/03/2015 
 *  Author: JRGandara
 */ 
#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>

#define F_CPU 4000000UL
#include <util/delay.h>
#include <string.h>
#include <stdbool.h>	
#include <sbit.h>		
#include <math.h>

#define LED_ON PORTA |= (1<<PA4)
#define LED_OFF PORTA &= ~(1<<PA4)
#define POWERKEY_HIGH PORTB |= (1<<PB1)
#define POWERKEY_LOW PORTB &= ~(1<<PB1)
#define DTR_ON PORTB |= (1<<PB3)
#define DTR_OFF PORTB &= ~(1<<PB3)

uint8_t flag_usart_rx;
uint8_t flag_rmc;
int rx_serial_string [70];		// Array de RX da UART
uint8_t prt_serial;	
uint8_t uart_getchar;
int baud = 25;					// 25=9600

uint8_t TX_SERIAL_GPS (char data)
{
	/* Wait for empty transmit buffer */
	while ( !( UCSR1A & (1<<UDRE1)) );
	/* Put data into buffer, sends the data */
	UDR1 = data;
	return (0);
}

uint8_t rx_serial ()
{
	if (flag_usart_rx==1)
	{
		flag_usart_rx=0;
		if (uart_getchar=='R' || flag_rmc==1)
		{
		rx_serial_string[prt_serial] = uart_getchar;			// Move string da UART no array
		prt_serial++;
		flag_rmc=1;
		}
		if (prt_serial==69)
		{
			prt_serial=0;
			flag_rmc=0;
			if (rx_serial_string [15]=='V')
				{
				LED_ON;
				}
			if (rx_serial_string [15]=='A')
				{
				LED_OFF;
				}
		}
		
	}
	return (0);
}

int main(void)
{
	DDRA=0b00010001;		//PA0=LED
	PORTA=0b00000000;
	DDRB=0b00001010;
	PORTB=0b00000010;
	DDRD=0b00000000;		//PA0=LED
	PORTD=0b00000000;

	UBRR1H = (unsigned char) (baud >> 8);	// define baud GPS
	UBRR1L = (unsigned char) baud;
	UCSR1B = (1<<TXEN1) | (1<<RXEN1);		// seta TX RX
	UCSR1C = (1<<UCSZ10)|(1<<UCSZ11);		// 8 bit
	UCSR1B |= (1 << RXCIE1);

	sei();

	while(1)
    {
		rx_serial();
	
		TX_SERIAL_GPS('G');
		TX_SERIAL_GPS('P');
		TX_SERIAL_GPS('S');
    }
}

ISR (USART1_RX_vect)
{
	uart_getchar = UDR1 ; // Fetch the received byte value into the variable " ByteReceived "
	flag_usart_rx=1;
}

Here is the .lss which I never was aware of:
 

 

STS500.elf:     file format elf32-avr
Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .data         00000002  00800100  000001bc  00000250  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  1 .text         000001bc  00000000  00000000  00000094  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .bss          00000090  00800102  00800102  00000252  2**0
                  ALLOC
  3 .comment      00000030  00000000  00000000  00000252  2**0
                  CONTENTS, READONLY
  4 .debug_aranges 00000038  00000000  00000000  00000282  2**0
                  CONTENTS, READONLY, DEBUGGING
  5 .debug_info   000001b4  00000000  00000000  000002ba  2**0
                  CONTENTS, READONLY, DEBUGGING
  6 .debug_abbrev 000000e6  00000000  00000000  0000046e  2**0
                  CONTENTS, READONLY, DEBUGGING
  7 .debug_line   0000011d  00000000  00000000  00000554  2**0
                  CONTENTS, READONLY, DEBUGGING
  8 .debug_frame  00000064  00000000  00000000  00000674  2**2
                  CONTENTS, READONLY, DEBUGGING
  9 .debug_str    00000197  00000000  00000000  000006d8  2**0
                  CONTENTS, READONLY, DEBUGGING
 10 .debug_loc    0000005b  00000000  00000000  0000086f  2**0
                  CONTENTS, READONLY, DEBUGGING
 11 .debug_ranges 00000028  00000000  00000000  000008ca  2**0
                  CONTENTS, READONLY, DEBUGGING
Disassembly of section .text:
00000000 <__vectors>:
   0:    0c 94 3e 00     jmp    0x7c    ; 0x7c <__ctors_end>
   4:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
   8:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
   c:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  10:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  14:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  18:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  1c:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  20:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  24:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  28:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  2c:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  30:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  34:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  38:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  3c:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  40:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  44:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  48:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  4c:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  50:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  54:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  58:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  5c:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  60:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  64:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  68:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  6c:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  70:    0c 94 c9 00     jmp    0x192    ; 0x192 <__vector_28>
  74:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
  78:    0c 94 5b 00     jmp    0xb6    ; 0xb6 <__bad_interrupt>
0000007c <__ctors_end>:
  7c:    11 24           eor    r1, r1
  7e:    1f be           out    0x3f, r1    ; 63
  80:    cf ef           ldi    r28, 0xFF    ; 255
  82:    d4 e0           ldi    r29, 0x04    ; 4
  84:    de bf           out    0x3e, r29    ; 62
  86:    cd bf           out    0x3d, r28    ; 61
00000088 <__do_copy_data>:
  88:    11 e0           ldi    r17, 0x01    ; 1
  8a:    a0 e0           ldi    r26, 0x00    ; 0
  8c:    b1 e0           ldi    r27, 0x01    ; 1
  8e:    ec eb           ldi    r30, 0xBC    ; 188
  90:    f1 e0           ldi    r31, 0x01    ; 1
  92:    02 c0           rjmp    .+4          ; 0x98 <__do_copy_data+0x10>
  94:    05 90           lpm    r0, Z+
  96:    0d 92           st    X+, r0
  98:    a2 30           cpi    r26, 0x02    ; 2
  9a:    b1 07           cpc    r27, r17
  9c:    d9 f7           brne    .-10         ; 0x94 <__do_copy_data+0xc>
0000009e <__do_clear_bss>:
  9e:    21 e0           ldi    r18, 0x01    ; 1
  a0:    a2 e0           ldi    r26, 0x02    ; 2
  a2:    b1 e0           ldi    r27, 0x01    ; 1
  a4:    01 c0           rjmp    .+2          ; 0xa8 <.do_clear_bss_start>
000000a6 <.do_clear_bss_loop>:
  a6:    1d 92           st    X+, r1
000000a8 <.do_clear_bss_start>:
  a8:    a2 39           cpi    r26, 0x92    ; 146
  aa:    b2 07           cpc    r27, r18
  ac:    e1 f7           brne    .-8          ; 0xa6 <.do_clear_bss_loop>
  ae:    0e 94 9f 00     call    0x13e    ; 0x13e <main>
  b2:    0c 94 dc 00     jmp    0x1b8    ; 0x1b8 <_exit>
000000b6 <__bad_interrupt>:
  b6:    0c 94 00 00     jmp    0    ; 0x0 <__vectors>
000000ba <TX_SERIAL_GPS>:
int baud = 25;                    // 25=9600
uint8_t TX_SERIAL_GPS (char data)
{
    /* Wait for empty transmit buffer */
    while ( !( UCSR1A & (1<<UDRE1)) );
  ba:    e8 ec           ldi    r30, 0xC8    ; 200
  bc:    f0 e0           ldi    r31, 0x00    ; 0
  be:    90 81           ld    r25, Z
  c0:    95 ff           sbrs    r25, 5
  c2:    fd cf           rjmp    .-6          ; 0xbe <TX_SERIAL_GPS+0x4>
    /* Put data into buffer, sends the data */
    UDR1 = data;
  c4:    80 93 ce 00     sts    0x00CE, r24
    return (0);
}
  c8:    80 e0           ldi    r24, 0x00    ; 0
  ca:    08 95           ret
000000cc <rx_serial>:
uint8_t rx_serial ()
{
    if (flag_usart_rx==1)
  cc:    80 91 04 01     lds    r24, 0x0104
  d0:    81 30           cpi    r24, 0x01    ; 1
  d2:    99 f5           brne    .+102        ; 0x13a <rx_serial+0x6e>
    {
        flag_usart_rx=0;
  d4:    10 92 04 01     sts    0x0104, r1
        if (uart_getchar=='R' || flag_rmc==1)
  d8:    80 91 05 01     lds    r24, 0x0105
  dc:    82 35           cpi    r24, 0x52    ; 82
  de:    21 f0           breq    .+8          ; 0xe8 <rx_serial+0x1c>
  e0:    90 91 03 01     lds    r25, 0x0103
  e4:    91 30           cpi    r25, 0x01    ; 1
  e6:    89 f4           brne    .+34         ; 0x10a <rx_serial+0x3e>
        {
        rx_serial_string[prt_serial] = uart_getchar;            // Move string da UART no array
  e8:    20 91 02 01     lds    r18, 0x0102
  ec:    e2 2f           mov    r30, r18
  ee:    f0 e0           ldi    r31, 0x00    ; 0
  f0:    ee 0f           add    r30, r30
  f2:    ff 1f           adc    r31, r31
  f4:    ea 5f           subi    r30, 0xFA    ; 250
  f6:    fe 4f           sbci    r31, 0xFE    ; 254
  f8:    90 e0           ldi    r25, 0x00    ; 0
  fa:    91 83           std    Z+1, r25    ; 0x01
  fc:    80 83           st    Z, r24
        prt_serial++;
  fe:    2f 5f           subi    r18, 0xFF    ; 255
 100:    20 93 02 01     sts    0x0102, r18
        flag_rmc=1;
 104:    81 e0           ldi    r24, 0x01    ; 1
 106:    80 93 03 01     sts    0x0103, r24
        }
        if (prt_serial==69)
 10a:    80 91 02 01     lds    r24, 0x0102
 10e:    85 34           cpi    r24, 0x45    ; 69
 110:    a1 f4           brne    .+40         ; 0x13a <rx_serial+0x6e>
        {
            prt_serial=0;
 112:    10 92 02 01     sts    0x0102, r1
            flag_rmc=0;
 116:    10 92 03 01     sts    0x0103, r1
            if (rx_serial_string [15]=='V')
 11a:    80 91 24 01     lds    r24, 0x0124
 11e:    90 91 25 01     lds    r25, 0x0125
 122:    86 35           cpi    r24, 0x56    ; 86
 124:    91 05           cpc    r25, r1
 126:    09 f4           brne    .+2          ; 0x12a <rx_serial+0x5e>
                {
                LED_ON;
 128:    14 9a           sbi    0x02, 4    ; 2
                }
            if (rx_serial_string [15]=='A')
 12a:    80 91 24 01     lds    r24, 0x0124
 12e:    90 91 25 01     lds    r25, 0x0125
 132:    81 34           cpi    r24, 0x41    ; 65
 134:    91 05           cpc    r25, r1
 136:    09 f4           brne    .+2          ; 0x13a <rx_serial+0x6e>
                {
                LED_OFF;
 138:    14 98           cbi    0x02, 4    ; 2
                }
        }
        
    }
    return (0);
}
 13a:    80 e0           ldi    r24, 0x00    ; 0
 13c:    08 95           ret
0000013e <main>:
int main(void)
{
    DDRA=0b00010001;        //PA0=LED
 13e:    81 e1           ldi    r24, 0x11    ; 17
 140:    81 b9           out    0x01, r24    ; 1
    PORTA=0b00000000;
 142:    12 b8           out    0x02, r1    ; 2
    DDRB=0b00001010;
 144:    8a e0           ldi    r24, 0x0A    ; 10
 146:    84 b9           out    0x04, r24    ; 4
    PORTB=0b00000010;
 148:    82 e0           ldi    r24, 0x02    ; 2
 14a:    85 b9           out    0x05, r24    ; 5
    DDRD=0b00000000;        //PA0=LED
 14c:    1a b8           out    0x0a, r1    ; 10
    PORTD=0b00000000;
 14e:    1b b8           out    0x0b, r1    ; 11
    UBRR1H = (unsigned char) (baud >> 8);    // define baud GPS
 150:    80 91 01 01     lds    r24, 0x0101
 154:    80 93 cd 00     sts    0x00CD, r24
    UBRR1L = (unsigned char) baud;
 158:    80 91 00 01     lds    r24, 0x0100
 15c:    80 93 cc 00     sts    0x00CC, r24
    UCSR1B = (1<<TXEN1) | (1<<RXEN1);        // seta TX RX
 160:    e9 ec           ldi    r30, 0xC9    ; 201
 162:    f0 e0           ldi    r31, 0x00    ; 0
 164:    88 e1           ldi    r24, 0x18    ; 24
 166:    80 83           st    Z, r24
    UCSR1C = (1<<UCSZ10)|(1<<UCSZ11);        // 8 bit
 168:    86 e0           ldi    r24, 0x06    ; 6
 16a:    80 93 ca 00     sts    0x00CA, r24
    UCSR1B |= (1 << RXCIE1);
 16e:    80 81           ld    r24, Z
 170:    80 68           ori    r24, 0x80    ; 128
 172:    80 83           st    Z, r24
    sei();
 174:    78 94           sei
    prt_serial=0;
 176:    10 92 02 01     sts    0x0102, r1
    while(1)
    {
        rx_serial();
 17a:    0e 94 66 00     call    0xcc    ; 0xcc <rx_serial>
    
        TX_SERIAL_GPS('G');
 17e:    87 e4           ldi    r24, 0x47    ; 71
 180:    0e 94 5d 00     call    0xba    ; 0xba <TX_SERIAL_GPS>
        TX_SERIAL_GPS('P');
 184:    80 e5           ldi    r24, 0x50    ; 80
 186:    0e 94 5d 00     call    0xba    ; 0xba <TX_SERIAL_GPS>
        TX_SERIAL_GPS('S');
 18a:    83 e5           ldi    r24, 0x53    ; 83
 18c:    0e 94 5d 00     call    0xba    ; 0xba <TX_SERIAL_GPS>
 190:    f4 cf           rjmp    .-24         ; 0x17a <main+0x3c>
00000192 <__vector_28>:
    }
}
ISR (USART1_RX_vect)
{
 192:    1f 92           push    r1
 194:    0f 92           push    r0
 196:    0f b6           in    r0, 0x3f    ; 63
 198:    0f 92           push    r0
 19a:    11 24           eor    r1, r1
 19c:    8f 93           push    r24
    uart_getchar = UDR1 ; // Fetch the received byte value into the variable " ByteReceived "
 19e:    80 91 ce 00     lds    r24, 0x00CE
 1a2:    80 93 05 01     sts    0x0105, r24
    flag_usart_rx=1;
 1a6:    81 e0           ldi    r24, 0x01    ; 1
 1a8:    80 93 04 01     sts    0x0104, r24
 1ac:    8f 91           pop    r24
 1ae:    0f 90           pop    r0
 1b0:    0f be           out    0x3f, r0    ; 63
 1b2:    0f 90           pop    r0
 1b4:    1f 90           pop    r1
 1b6:    18 95           reti
000001b8 <_exit>:
 1b8:    f8 94           cli
000001ba <__stop_program>:
 1ba:    ff cf           rjmp    .-2          ; 0x1ba <__stop_program>

 

Those bad interrupt smells something?

Good Soldering JRGandara

Last Edited: Thu. May 21, 2015 - 11:16 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have not read your code, but shared variables (ISR and main) are not volatile.

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

As it happens the code in this case (according to the .lss) doesn't need volatile as it accesses 0x104 and 0x105 anyway - but this was just luck. You are right they should be volatile but that is not the issue in this particular case.

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

If was the prt_serial=0 you mean it should not be there. I deleted.

Good Soldering JRGandara

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

Just try this:

#include <avr/io.h>

#define F_CPU 4000000UL

int baud = 25;					// 25=9600

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

int main(void)
{
	UBRR1H = (unsigned char) (baud >> 8);	// define baud GPS
	UBRR1L = (unsigned char) baud;
	UCSR1B = (1<<TXEN1) ;		// seta TX 

	while(1)
    {
		TX_SERIAL_GPS('U');
    }
}

Put a scope probe on the TXD pin and measure the width of a low or a high (it should be alternating). Is it 104us ?

 

As a secondary check get out your ISP programmer and activate CKOUT (bit 6) in the low fuse byte. Now put your scope probe on pin 2. Do you see 4MHz there?

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

Clawson,

 

Wow! I liked your FAQ tips. I will stop everything now to read them all. 

 

Well, looks like I found the main problem. I don´t know exactly the reason, but now I can go on. I have some spare boards of this same prototype and in the other 3 boards the serial transmission work just fine. Sorry for taking your time just to learn it was a hardware problem. 

Now the transmission is ok, but I´m not receiving the NMEAs strings in the RX1. Probing with the scope at RX1 input pin shows a OK signal from GPS. This code below was working before, so must be some setting problem I messed up. 

The idea is to get saved part of the NMEA RMC string and check if a specific character is V (invalid) or A (valid), and turn the LED on or off accordingly.

Good Soldering JRGandara

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

Why don't you implement this properly?

 

Start with an RXC interrupt and a FIFO. Then add stdio above this. Then simply use an off the shelf NMEA parsing library.

 

While I suppose it's fun to muddle along and gradually re-invent this particular wheel if the goal here is simply to get on with the job of using NMEA to do something more interesting at the higher level (all the usual great circles thing and so on) then don't mess around with the basic details. Just use proven solutions and move on to the more interesting, high level stuff.

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

I don't know you GPS but if it a NMEA 0183 version

it's 4800 baud!

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

You can just start with library working out of the box.

 

BTW - what was the problem ?

Last Edited: Thu. May 21, 2015 - 01:27 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh my... One more hardware problem. There was a resistor between the TXD output line of the GPS module to RXD input line of the AVR. This resistor should be around 1K, but was mistaken by 1M. Now everything is working fine. Sorry all.

This is a Globalsat EB5662 module which came with 9600 default. This make sense? Should come set with 4800?

Now I will read more about USART and check the RXC interrupt and FIFO which Clawson mentioned and I´m not familiar.

 

Thank you all.

Good Soldering JRGandara