USART hang problems

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

My USART start to hang wothout any reaon and I don't know why.

 main.c

#include "main.h"

#define LED_PORT PORTA
#define LED_DIR DDRA
#define LED_PIN0 0
#define LED_PIN1 1
#define LED_PIN2 2
#define LED_PIN3 3
#define LED_PIN4 4
#define LED_PIN5 5
#define LED_PIN6 6
#define LED_PIN7 7

ISR (USART_RXC_vect) {
	LED_PORT |= (1<<LED_PIN0);
	//_delay_ms(100);		
}

SR(USART_TXC_vect) {
	LED_PORT |= (1<<LED_PIN1);
	//_delay_ms(100);	
}

int main(void) {
	PORTA = 0x00;
	DDRA = 0xFF;
	
	USART_Init(16);	
	
	sei();
	
	USART_SendString("Testing send info");

	
    while (1) {
		LED_PORT &= ~(1<<LED_PIN0);
		LED_PORT &= ~(1<<LED_PIN1);
		LED_PORT &= ~(1<<LED_PIN2);
		LED_PORT &= ~(1<<LED_PIN3);
		LED_PORT &= ~(1<<LED_PIN4);
		LED_PORT &= ~(1<<LED_PIN5);
		LED_PORT &= ~(1<<LED_PIN6);
		LED_PORT &= ~(1<<LED_PIN7);
    }
}

main.h

#ifndef MAIN1_H_
#define MAIN1_H_

#define F_CPU 16000000UL

#include <avr/io.h>
#include <avr/delay.h>
#include <avr/interrupt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "USART.h"

#endif /* MAIN1_H_ */

USART.c

#include "USART.h"

void USART_Init(unsigned int speed) {	
	UBRRH = (unsigned char)(speed>>8);
	UBRRL = (unsigned char)speed;
	UCSRB |= (1<<RXEN)|(1<<TXEN);
	UCSRB |= (1<<RXCIE)|(1<<TXCIE);
	UCSRA |= (1<<U2X);
	UCSRC |= (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);
}

void USART_Transmit(unsigned char data) {
	while(!(UCSRA & (1<<UDRE)));
	UDR = data;
}

void USART_SendString(char * s) {
	while(*(s)!='\0') {
		USART_SendChar(*(s++));
	}
}

void USART_SendChar(unsigned char symbol) {
	while(!(UCSRA & (1<<UDRE)));
	UDR = symbol;
}

USART.h

#ifndef USART_H_
#define USART_H_
#include "main.h"

void USART_Init(unsigned int speed);
void USART_Transmit(unsigned char data);
void USART_SendString(char * s);
void USART_SendChar(unsigned char symbol);

#endif /* USART_H_ */

From start point - when I program my ATmega16 LED0 ON (USART read some data...I dotn't know from were) and newer OFF.

I connect  my ATmega16 to  USB-USART module based on PL2303 chip  + I use Terminal v1.9b to monitor info. And I see "Testing send info" as resolt send info by USART from ATmega16.

When I disconnect from USB my USB-USART module LED0 still ON...but must be OFF (no data transfer from USB to ATmega16).

So USART hang...I don't know reason.

Last Edited: Mon. Apr 1, 2019 - 12:38 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For starters:

 

What does 16 for "SPEED" relate to in baud rate?

 

also this:

#define LED_PIN0 0
#define LED_PIN1 1

you might want to try:

#define LED_PIN0 0x01
#define LED_PIN1 0x02
#define LED_PIN2 0x04
#define LED_PIN3 0x08

and so on.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

jgmdesign wrote:

For starters:

 

What does 16 for "SPEED" relate to in baud rate?

 

also this:

#define LED_PIN0 0
#define LED_PIN1 1

you might want to try:

#define LED_PIN0 0x01
#define LED_PIN1 0x02
#define LED_PIN2 0x04
#define LED_PIN3 0x08

and so on.

 

JIm

115.2kBaud

You may check this topic: https://www.avrfreaks.net/forum/...

We discuss baud rate for USART allready.

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

as you already have a thread running on this issue there is no reason to start another thread?

 

I'll lock this one

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

Last Edited: Mon. Apr 1, 2019 - 12:38 PM
Topic locked