Problem with EUSART on PIC18F4520.

Status
Not open for further replies.

Pheetuz

Full Member level 3
Joined
Feb 12, 2010
Messages
162
Helped
21
Reputation
42
Reaction score
19
Trophy points
1,298
Location
Brighton
Activity points
2,835
Hi folks.

I am trying to communicate from a PIC18F4520 to another PIC18F4520, however for the time being I am just trying to transmit data out of one PIC to an oscilloscope, just to ensure that I am actually transmitting which it appears I'm not.

I have to configuration bits on the PIC set up in the PIC menu, and am using a 10MHz crystal on a PICDEM2 board.

All I want to do is transmit a series of 1s and 0s which is why 0xAA is being fed into TXREG.

I have the oscilloscope triggering set up so that I would be able to see a change on the screen but nothing is happening when I load data into the TXREG.

If anyone can see anything wrong with my code it would be much appreciated.

Code:
#include <P18F4520.h>
#include <stdio.h>
#include <usart.h>

void main (void)

{

//CONFIGURES THE PORTS

ADCON0	=	16;
CMCON	=	7;
TRISA	=	255;
TRISB	=	255;
TRISC	=	255;

// CONFIGURES THE USART.

TXSTA	=	176;
RCSTA	=	128;
BAUDCON	=	24;
SPBRG	=	255;
SPBRGH	=	255;

//TEST

TXREG = 0xAA;


while(1){}

}

Pete
 

Check the configuration bit you need to set again. Most likely some bits are missing.

---------- Post added at 11:48 ---------- Previous post was at 11:46 ----------

This is sample of UART for PIC18F2550:

//#define USE_OR_MASKS
#include <P18f2550.h>
#include <usart.h>
//-------------------------------Configuration setting ----------------------------------------------

unsigned char Rxdata[25];
unsigned char Txdata[] = "MICROCHIP_USART";

// BAUD_RATE_GEN is calculated as = [Fosc / (64 * Desired Baudrate)] - 1
// It needs to be changed depending upon oscillator frequency.
// 8MHz / (64 * 2400) - 1 = 51 (approx.)
#define BAUD_RATE_GEN 51 // Fosc = 8MHz, Baud Rate = 2400 bps

void main(void)
{
//-------------------------configure USART ---------------------------------------------------------
// API configures USART for desired parameters:
// - TX/RX interrupts turned off
// - Asynchronous mode
// - 8 bits
// - Continuous Receive Enabled
// - Low speed baud rate generator mode (Fosc / 16)
OpenUSART(USART_TX_INT_OFF | USART_RX_INT_OFF | USART_ASYNCH_MODE | USART_EIGHT_BIT | USART_CONT_RX | USART_BRGH_LOW, BAUD_RATE_GEN);
//baudUSART(BAUD_8_BIT_RATE | BAUD_AUTO_OFF);


//------------USART Transmission ----------------------------------------------------------------
putsUSART((char *)Txdata); // transmit the string

//-----------USART Reception ---------------------------------------------------------------------
getsUSART((char *)Rxdata, 24); // receive data up to 24 bytes
Rxdata[24] = 0; // NULL terminate the string for putsUSART call.
putsUSART((char *)Rxdata); // echo back the data recieved back to host

CloseUSART();
while(1); // end of program
}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…