Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with UART communication using PIC32MX220F032B

Status
Not open for further replies.

DatsAbk

Member level 3
Joined
Jun 22, 2012
Messages
55
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,704
hello,
I have been trying this out since 3 days and continuously facing the same problem after trying all I know.
The problem I am facing is that when I send a byte the MSB sent is always '1' and the 3rd bit starting from LSB is skipped. A really strange thing.

The data I receive is as under

Sent Data Received Data on other board
0x01 0x81
0x02 0x82
0x03 0x83
0x04 0x80 that is the 3rd bit is skipped in data
0x05 0x81 again 3rd bit is skipped and 8th bit is always '1'
0x06 0x82
0x07 0x83

My code is as below:
Code:
// PIC32MX220F032B Configuration Bit Settings


// PIC32MX220F032B Configuration Bit Settings
#include <p32xxxx.h>
// DEVCFG3// USERID = No Setting
#pragma config PMDL1WAY = ON            // Peripheral Module Disable Configuration (Allow only one reconfiguration)
#pragma config IOL1WAY = ON            // Peripheral Pin Select Configuration (Allow multiple reconfigurations)
#pragma config FUSBIDIO = ON            // USB USID Selection (Controlled by the USB Module)
#pragma config FVBUSONIO = ON           // USB VBUS ON Selection (Controlled by USB Module)
// DEVCFG2
#pragma config FPLLIDIV = DIV_1         // PLL Input Divider (1x Divider)
#pragma config FPLLMUL = MUL_16         // PLL Multiplier (16x Multiplier)
#pragma config UPLLIDIV = DIV_12        // USB PLL Input Divider (12x Divider)
#pragma config UPLLEN = OFF             // USB PLL Enable (Disabled and Bypassed)
#pragma config FPLLODIV = DIV_16        // System PLL Output Clock Divider (PLL Divide by 16)
// DEVCFG1
#pragma config FNOSC = FRCDIV           // Oscillator Selection Bits (Fast RC Osc w/Div-by-N (FRCDIV))
#pragma config FSOSCEN = OFF            // Secondary Oscillator Enable (Disabled)
#pragma config IESO = ON                // Internal/External Switch Over (Enabled)
#pragma config POSCMOD = HS             // Primary Oscillator Configuration (HS osc mode)
#pragma config OSCIOFNC = OFF           // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_4           // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/4)
#pragma config FCKSM = CSDCMD           // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled)
#pragma config WDTPS = PS1048576        // Watchdog Timer Postscaler (1:1048576)
#pragma config WINDIS = OFF             // Watchdog Timer Window Enable (Watchdog Timer is in Non-Window Mode)
#pragma config FWDTEN = OFF             // Watchdog Timer Enable (WDT Disabled (SWDTEN Bit Controls))
#pragma config FWDTWINSZ = WISZ_25      // Watchdog Timer Window Size (Window Size is 25%)
// DEVCFG0
#pragma config JTAGEN = OFF             // JTAG Enable (JTAG Disabled)
#pragma config ICESEL = ICS_PGx1        // ICE/ICD Comm Channel Select (Communicate on PGEC1/PGED1)
#pragma config PWP = OFF                // Program Flash Write Protect (Disable)
#pragma config BWP = OFF                // Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF                 // Code Protect (Protection Disabled)



#define PPSUnLock() {SYSKEY=0x0;SYSKEY=0xAA996655;SYSKEY=0x556699AA;CFGCONbits.IOLOCK=0;}
#define PPSLock() {SYSKEY=0x0;SYSKEY=0xAA996655;SYSKEY=0x556699AA;CFGCONbits.IOLOCK=1;}
void main()
{   
unsigned int i;   
unsigned int j=0x000001;   
ANSELB=0;   
PPSUnLock();   
CFGCONbits.IOLOCK=0;   
TRISBbits.TRISB3=0;   
RPB3Rbits.RPB3R=1;   
TRISBbits.TRISB2=1;   
U1RXRbits.U1RXR=4;   
PPSLock();       
U1MODEbits.UEN=0;   
U1MODEbits.ON=1;   
U1MODEbits.SIDL=0;   
U1MODEbits.IREN=0;   
U1MODEbits.WAKE=0;   
U1MODEbits.LPBACK=0;   
U1MODEbits.ABAUD=0;   
U1MODEbits.BRGH=1;   
U1MODEbits.PDSEL=0;   
U1MODEbits.STSEL=0;   
U1MODEbits.RXINV=0;   
U1STAbits.URXISEL=0;   
U1STAbits.UTXISEL=0;   
U1STAbits.URXEN=1;   
U1STAbits.UTXBRK=0;   
U1STAbits.UTXEN=1;   
U1STAbits.UTXBF=0;   
U1STAbits.TRMT=0;   
U1STAbits.ADDEN=0;   
U1STAbits.UTXINV=0;       
U1BRG=10;
    while(1)   
{       
while (U1STAbits.UTXBF);  // wait until transmit buffer empty       
U1TXREG=j;       
j=j+1;       
for(i=0;i<32750;i++);                       //Provide a random delay       
for(i=0;i<32750;i++);       
for(i=0;i<32750;i++);       
for(i=0;i<32750;i++);       
for(i=0;i<32750;i++);       
for(i=0;i<32750;i++);



    }

    }
 

How do you receive the data? What's the hardware connection?

My suggestion, use PLIB to configure the processor and UART, check PLIB UART examples. I must confess, I'm not motivated to go through the various register settings.
Check correct baudrate and framing with an oscilloscope.
 

How do you receive the data? What's the hardware connection?

My suggestion, use PLIB to configure the processor and UART, check PLIB UART examples. I must confess, I'm not motivated to go through the various register settings.
Check correct baudrate and framing with an oscilloscope.

Hello FvM, thankyou for your response. I've configured almost perfectly well. I've checked the baud rate on CRO. The baud seems to be ok. I'm not perfectly sure. On the other hand I have a PIC18f4550 development board which receives and displays data on LED.

I also need guidance on how to use plib as I'm unable to understand that well
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top