CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

rs232 reverse

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ccsx3



Joined: 06 Jan 2013
Posts: 6

View user's profile Send private message

rs232 reverse
PostPosted: Tue Jul 08, 2014 9:02 am     Reply with quote

hi
im trying to send some midi word via rs232 with DSPIC33EP512MU814
but after i got no response from the slave midi i decided to check it with scope
and i find that my word are reverse.

Code:

#use RS232(xmit=PIN_G1,rcv=PIN_G0,baud=31250,UART2,STOP=1,PARITY=N,BRGH1OK,BITS=8,stream=midi232) // midi out/in


Code:

//////////////////////////////////////////////////////
//====================send_midi=======================
void send_midi(unsigned char b1, unsigned char b2, unsigned char b3)
{
output_high(PIN_F3); //enable
  putc(b1,midi232);   //putc(integer,name uart);
  putc(b2,midi232);
  putc(b3,midi232);   
 }   

//==================send_midi==========================
///////////////////////////////////////////////////////


the problems is in the uart define or i need to send it reverse from the start?
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Jul 08, 2014 9:15 am     Reply with quote

Hi,

If you mean that bytes are being received b1, then b2, then b3, but you really need them to be received b3, then b2, then b1, then simply reverse the order that they are sent in your code. This is not a UART configuration issue.

John
ccsx3



Joined: 06 Jan 2013
Posts: 6

View user's profile Send private message

PostPosted: Tue Jul 08, 2014 9:22 am     Reply with quote

nope its not my problem

i send
send_midi(0b10001011,0b00100100,0b00010010);

and i get in my scope :

ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Jul 08, 2014 9:35 am     Reply with quote

Hi,

There is an expectation that some sort of hardware inversion will take place between the PIC UART and the receiver. For example, you would use a MAX232 IC between the PIC UART and a PC COM port. The MAX232 inverts both the Tx and Rx signals.

If you need non-inverted data, you have two choices. Add hardware inverters to the UART Tx output and Rx input, or add the 'Invert' option to the #use_rs232' directive. The (major) downside of the 2nd option is that the compiler will automatically create a 'software' serial port when this option is specified.

John
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jul 08, 2014 9:36 am     Reply with quote

hmmmm.... without a reference I can't tell what the 'scope' is supposed to be....

but....

do you mean the '1's are '0's and '0's are '1's ???

If so that's the PIC to MIDI interface.

I'd have to see a schematic of it, it could be as simple as connecting the PIC to the anode of the optocoupler with cathode tied to ground via a resistor or the 'other way round' .

Again, a picture is worth 1000 words.

jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 08, 2014 10:35 am     Reply with quote

He is looking at the output of the PIC's Tx pin with his scope.
His complaint is that the bits are coming out LSB-first.

Download the dsPIC33 UART Reference Manual:
http://ww1.microchip.com/downloads/en/DeviceDoc/70000582e.pdf
The pertinent line from that manual is given in bold below:
Quote:

4.0 UART CONFIGURATION
The UART uses the standard Non-Return-to-Zero (NRZ) format (one Start bit, eight or nine Data bits and one or two Stop bits).
.
.
.
The UART transmits and receives the Least Significant bit (LSb) first.
The transmitter and receiver of the UART module are functionally
independent, but use the same data format and baud rate.

In other words, what he is seeing is completely normal. The UART sends
data LSB first.
ccsx3



Joined: 06 Jan 2013
Posts: 6

View user's profile Send private message

PostPosted: Tue Jul 08, 2014 10:40 am     Reply with quote

thanks a lot PCM programmer and others Smile
ur answer help me to understand the problem

there is a way that i can invert it without change components but still use uart hardware ?
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jul 08, 2014 10:46 am     Reply with quote

yes....
create a function that create a new byte that is the 'mirror' image of the original.
ie: new bit7 == old bit0, new bit7 == old bit1 , etc.
CCS does supply 'bit' functions so it really is only 8-10 lines of extra code.


there might be a code snippet on the forum....
maybe search for 'reverse order bits' ?

hth
jay
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jul 08, 2014 10:49 am     Reply with quote

hmmm..... since it's raining cats,dogs and giraffes here...

http://www.ccsinfo.com/forum/viewtopic.php?t=23364&highlight=reverse+order

might be a good place to start....


jay
ccsx3



Joined: 06 Jan 2013
Posts: 6

View user's profile Send private message

PostPosted: Tue Jul 08, 2014 11:00 am     Reply with quote

hoo thanks i thought it can solved by add invert somewhere XD
without use some funcs... but thanks again
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Wed Jul 09, 2014 3:03 am     Reply with quote

Well surely you can do it without having any reverse bit functions.

Code:
send_midi(0b10001011,0b00100100,0b00010010);


becomes

Code:
send_midi(0b11010001,0b00100100,0b01001000);
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jul 09, 2014 7:55 am     Reply with quote

oxo...

please show us how you did it !

jay
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Wed Jul 09, 2014 8:01 am     Reply with quote

temtronic wrote:
oxo...

please show us how you did it !

jay


I can't, it j-j-just happened. I can't explain it. It'll probably never happen again.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group