Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

EUSART not working properly

Status
Not open for further replies.

mikesmixes

New Member
Hi,

I am trying to configure the EUSART in a PIC18F2620....

See attached code.

The problem is that I recieve the correct characters but also the incorrect characters...
like happy faces and W's and > when all I should be receiving is T's.

Even when writing a String, there were incorrect characters withing the String.

Thanks.
Mike

Code:
//Library includes
#include <p18f2620.h>
#include <usart.h>

//My includes
#include "Main.h"

#pragma config OSC = HS //Oscilator = High Speed
#pragma config WDT = OFF //Watch Dog timer = ON
#pragma config PWRT = OFF //Power up timer OFF
#pragma config LVP = OFF //Low Voltage Programming = OFF


void InitializeBoard()
{
	TRISCbits.TRISC1 = 0; //LED to show button pressed
}

void ConfigureUSART()
{
	// configure USART Fosc=25Mhz, BR=19200, 8bits,
	OpenUSART( USART_TX_INT_OFF &
	USART_RX_INT_OFF &
	USART_ASYNCH_MODE &
	USART_EIGHT_BIT &
	USART_CONT_RX &
	USART_BRGH_HIGH,
	80 );

	//Enhanced USART Configuration
	baudUSART (BAUD_IDLE_CLK_LOW &
	BAUD_8_BIT_RATE &
	BAUD_WAKEUP_ON &
	BAUD_AUTO_OFF);
}

void main(void)
{
	int busy = 0; //USART Busy
	int buttonState = 0; //Last button state to detect falling edge
	int send = 0; //Send request

	InitializeBoard();
	ConfigureUSART();

	while(1)
	{
		PORTCbits.RC1 = !PORTBbits.RB5; //Set state of LED

		if( PORTBbits.RB5 < buttonState ) //Detect falling edge
		{
			send = 1;	
		}

		busy = BusyUSART();
		if(!BusyUSART() && send ) //Send required and USART available
		{
//			putrsUSART( "Test String, button pressed\n" );
			WriteUSART('T'); //Send just one char
			send = 0; //reset send request
		}

		buttonState = PORTBbits.RB5; //Set last state of button
	}
}
 
Have you double checked the baud rate being used at both ends? Do they match? Is this on a breadboard? Have you checked for loose connections?
 
Yes, I have double checked the baud rate both ends. I am using a pcb based around Jorge's EIP-10 Ethernet board.
Does the configuration seem correct? I have checked it, but maybe I'm missing something.

Thanks.
 
Apart from the comment that the WDT should be on but set to off, everything else looks ok.
80 is the correct setting for the baud rate generator, one thing I am not to familiar with is the EUSART baud settings, however, I am aware of this:
Inconsistencies in baudUSART()

It discusses some inconsitencies with the baudUSART function, may be worth a look.

Wilksey
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top