It is currently Sun Apr 20, 2014 2:19 pm



Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: Setting 9600,e,8,1 on the UART
PostPosted: Tue Feb 14, 2012 2:02 am 
Offline

Joined: Fri Feb 10, 2012 12:36 am
Posts: 79
Hello All,



I would recommend changing the UxMODE (where x is the number of the UART you are using) register directly, it will give you more control over the functionality of the UART. For example if you wish to set the UART1 to 8 data bits, even parity and 1 stop bits you would use:



U1MODE = 0;

U1MODESET = (1 << 15) | (1 << 1); //15 is the on bit and 1 is the 8-data + even parity bit.



This is detailed in the PIC32MX datasheet located



UART Specific:

http://ww1.microchip.com/downloads/en/D ... 61107F.pdf



Full PIC32MX

http://ww1.microchip.com/downloads/en/D ... 61143B.pdf



Best Regards,

Ryan


Top
 Profile  
 
 Post subject: Re: Setting 9600,e,8,1 on the UART
PostPosted: Fri Mar 02, 2012 9:41 pm 
Offline

Joined: Fri Dec 30, 2011 11:23 pm
Posts: 14
Thanks for that! :) Will give it a wurl as the other ways are just not working for me


Top
 Profile  
 
 Post subject: Re: Setting 9600,e,8,1 on the UART
PostPosted: Sat Mar 03, 2012 2:09 am 
Offline

Joined: Fri Feb 10, 2012 12:36 am
Posts: 79
Oh whoops I almost forgot you probably have to add #include <plib.h>


Top
 Profile  
 
 Post subject: Re: Setting 9600,e,8,1 on the UART
PostPosted: Mon Mar 12, 2012 11:48 am 
Offline

Joined: Sat Mar 10, 2012 7:50 am
Posts: 1
Software UART written in C language for atmega8? i want to increase serial port of atmega8 (which have 1 serial port,where i need 3 serial port) by using software uart .plz help me.
___________________________
keyword research ~ keyword tool ~ keyword tracking ~ affiliate elite


Top
 Profile  
 
 Post subject: Re: Setting 9600,e,8,1 on the UART
PostPosted: Sun Apr 29, 2012 2:17 am 
Offline

Joined: Fri Dec 30, 2011 11:23 pm
Posts: 14
Hi guys,

I have dedicated my weekend to working this out .. I have successfully managed to make this work on the Ardiuno Mega 2560 without any issue however when I use any of the code about its just not switching it to even parity.

I am running a 'sniffer' on the line and its still transmitting 9600,n,8,1 not 9600,e,8,1

Again the sniffer confirms the Ardiuno Mega 2560 is infact running 9600,e,8,1 however not the Max32 with the below code or any other in this thread.

here is what I have

Code:
#include <plib.h>

void setup() {
// Setup serial monitor coms
Serial.begin(9600);
Serial3.begin(9600);
U4MODE = 0;

U4MODESET = (1 << 15) | (1 << 1); //15 is the on bit and 1 is the 8-data + even parity bit.

}


Note i'm trying to send out and recieve commands on the last UART or RX3/TX3


Top
 Profile  
 
 Post subject: Re: Setting 9600,e,8,1 on the UART
PostPosted: Sun Apr 29, 2012 4:33 am 
Offline

Joined: Fri Dec 30, 2011 11:23 pm
Posts: 14
Reading some of the spec.

Code:
bit 2-1 PDSEL<1:0>: Parity and Data Selection bits
11 = 9-bit data, no parity
10 = 8-bit data, odd parity
01 = 8-bit data, even parity
00 = 8-bit data, no parity


The synatax is still confusing me a little with the U4MODESET command.

Doing a lot of searching on this there doesnt seem to be a lot of info on this with examples :(

Does the 4 in U4MODESET = the last UART (serial3 in MPIDE)?
Does setting Bit1 to 1 actually set it to binary '01' in U4MODESET = (1 << 15) | (1 << 1); ?


Top
 Profile  
 
 Post subject: Re: Setting 9600,e,8,1 on the UART
PostPosted: Mon Apr 30, 2012 8:14 am 
Offline

Joined: Fri Dec 30, 2011 11:23 pm
Posts: 14
Persistance paid off.

This is the code that works for RX3/TX3 (Serial3) pins on Chipkit Max32

Code:
#include <plib.h>

void setup() {

// Setup serial monitor coms
Serial3.begin(9600);

// Switch UxMODE register -  15 is the on bit and 1 is the 8-data + even parity bit.

U5MODESET = (1 << 15) | (1 << 1);

}


Thanks to all that helped out and I hope this helps some one else out in their travels :)


Top
 Profile  
 
 Post subject: Re: Setting 9600,e,8,1 on the UART
PostPosted: Sun May 06, 2012 1:58 am 
Offline

Joined: Fri Dec 30, 2011 11:23 pm
Posts: 14
Hmmm so it turns out with a lot of testing that unfortunately Im only half way there.

The above code works and allows the Max32 to transmit in 9600,e,8,1 however there is nothing on the recieve buffer at all.

I have tested with very back to basics code but all that I can get back is nothing.

The my send command is defanitely coming out of the Max32 in even parity. I have tested this with a sniffer on the line and the device im sending the command too is replying back correctly.

The Max32/pic32 just isnt recieveing.

I a friend and I have tested the hardware chain and voltages and they are all working 100%

Again we have tested the same code with a Ardiuno Mega 2560 and it works 100%

I have even attempted some more register 'SET' commands based on the UART documentation to force things like TX/RX on etc but with no luck there either.
Im still using the SerialX.begin(9600) command (which I assume covers off a lot of the register setting in one command) and over lay the UxMODESET commands over the top.

I have also used a second Max32 and tested the code to make sure i hadn't blown the RX part of the silicon on mine. Same results with this one too.

Kind of at a real loss of what to try next :(

Any expert help would be much appriecated.
I'm really keen on using the PIC32 for its out right grunt but I may have to change platforms to get on with this project.


Top
 Profile  
 
 Post subject: Re: Setting 9600,e,8,1 on the UART
PostPosted: Sun May 06, 2012 10:23 pm 
Offline

Joined: Mon Aug 29, 2011 4:18 pm
Posts: 104
Location: UK
Having enabled parity , what about parity error interrupts ,

INTERRUPTS
The UART can generate interrupts reflecting the events that occur during the data
communication. The following interrupts can be generated:
• Receiver-data-available interrupt, signalled by UxRXIF. This event occurs based on the
URXISEL<1:0> control bits (UxSTA<7:6>). Refer to 21.6.3 “Receive Interrupt” for details.
• Transmitter buffer-empty interrupt, signalled by UxTXIF. This event occurs based on the
UTXISEL<1:0> control bits (UxSTA<15:14>). Refer to 21.5.2 “Transmit Interrupt” for
details.
• UART-error interrupt, signalled by UxEIF.
- This event occurs when any of the following error conditions take place:
• Parity error PERR (UxSTA<3>) is detected
• Framing Error FERR (UxSTA<2>) is detected
• Overflow condition for the receive buffer OERR (UxSTA<1>) occurs
All these interrupt flags must be cleared in software. Refer to 21.5.2 “Transmit Interrupt” and
21.6.3 “Receive Interrupt” for more information.
A UART device is enabled as a source of interrupts through the following respective UART
interrupt enable bits:
• UxRXIE
• UxTXIE
• UxEIE

Can you see errors when reading UxSTA .
can you loopback tx--Rx .

Not an expert...... :(


Top
 Profile  
 
 Post subject: Re: Setting 9600,e,8,1 on the UART
PostPosted: Mon May 07, 2012 4:59 am 
Offline

Joined: Fri Dec 30, 2011 11:23 pm
Posts: 14
I'll look at the other stuff you've posted tonight ...



les1943 wrote:
Can you see errors when reading UxSTA .
can you loopback tx--Rx .



I have run up my code in a loop back (serial1->serial3)

The strange thing is, when I display it in the serial monitor .. with Even parity turned on for serial1 the byte array dump to the serial monitor (serial.print) display without being garbled .. which is very strange. I would execpt it to be inputting rubbish however it comes through as normal.

Here is the code with some random bytes sent



NOTE: I have not set the recieve port to even parity delibrately (its remmed out) you can enable it by unremarking U5MODESET command.


Code:
#include <plib.h>

byte inByte[4];

void setup() {

Serial.begin(9600);
Serial1.begin(9600);
Serial3.begin(9600);

U4MODESET = (1 << 15) | (1 << 1);     //(Serial1)  15 is the on bit and 1 is the '8-data + even parity bit' (See PIC32 UART Datasheet for more detail).

//  U5MODESET = (1 << 15) | (1 << 1);     //(Serial3)  15 is the on bit and 1 is the '8-data + even parity bit' (See PIC32 UART Datasheet for more detail).

}

void loop() {
byte SendByte[] = {char(1), char(2), char(3), char(4)};

// Send message
int i;
  for (i=0;i<4;i++){
  Serial1.print(SendByte[i]);
}

// Recieve response

if (Serial3.available()){
int r;
  for (r=0;r<4;r++){
  inByte[r] = Serial3.read();

   // Display in Serial Monitor

Serial.print(inByte[r], HEX);
  }
}
 
// Line feed and Delay
Serial.println("");
delay(1000);

}



Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2, 3  Next

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Theme designed by stylerbb.net © 2008
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All times are UTC [ DST ]