View previous topic :: View next topic |
Author |
Message |
ccsx3
Joined: 06 Jan 2013 Posts: 6
|
rs232 reverse |
Posted: Tue Jul 08, 2014 9:02 am |
|
|
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
|
|
Posted: Tue Jul 08, 2014 9:15 am |
|
|
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
|
|
Posted: Tue Jul 08, 2014 9:22 am |
|
|
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
|
|
Posted: Tue Jul 08, 2014 9:35 am |
|
|
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: 9216 Location: Greensville,Ontario
|
|
Posted: Tue Jul 08, 2014 9:36 am |
|
|
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
|
|
Posted: Tue Jul 08, 2014 10:35 am |
|
|
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
|
|
Posted: Tue Jul 08, 2014 10:40 am |
|
|
thanks a lot PCM programmer and others
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: 9216 Location: Greensville,Ontario
|
|
Posted: Tue Jul 08, 2014 10:46 am |
|
|
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: 9216 Location: Greensville,Ontario
|
|
|
ccsx3
Joined: 06 Jan 2013 Posts: 6
|
|
Posted: Tue Jul 08, 2014 11:00 am |
|
|
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
|
|
Posted: Wed Jul 09, 2014 3:03 am |
|
|
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: 9216 Location: Greensville,Ontario
|
|
Posted: Wed Jul 09, 2014 7:55 am |
|
|
oxo...
please show us how you did it !
jay |
|
|
oxo
Joined: 13 Nov 2012 Posts: 219 Location: France
|
|
Posted: Wed Jul 09, 2014 8:01 am |
|
|
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. |
|
|
|