News:

;) This forum is the property of Proton software developers

Main Menu

Serin true or inverted?

Started by broderic, Jan 30, 2022, 04:21 PM

Previous topic - Next topic

broderic

Hello.
    Device 16F876A                              ' device name
    Declare Xtal = 10
    Symbol TPin PORTC.6                        ' transmit pin
    Symbol RPin PORTC.7                        ' RX Pin
    Dim i As Byte                              ' loop counter
Main:
    For i = 0 To 9 Step 1
        SerOut TPin,6,["i: ",Dec i,13]
    Next

    End
Trying to run this simple code, with RS232 cable connected to Easypic v7, which has the MAX232 receiver transceiver, I found necessary, with baud rate 38400, to put baudmode=6 (according to calculation on page 248 of the manual).

But 6 is the value necessary for true mode, not for inverted mode, the one I'm working with on the board.
I should expected 16384+6, as it's written on the table for inverted mode.
I don't understand.
Thanks for any clarification.

Regards.

top204

I've altered the above post, so that all the code is within the code block, and not seperate lines of code blocks that makes things very awkward to read.

See the manual's section on Serout and Serin for the calculation required for the Baud and the True or Inverted mode.

If you take a look at the "Proton_10.inc" file that used to be used for the Proton boards, you will see some constants that represent the Baud modes for Serin and Serout:

    Symbol T300 = 3313
    Symbol N300 = 3313 + $4000
    Symbol T600 = 1646
    Symbol N600 = 1646 + $4000
    Symbol T1200 = 813
    Symbol N1200 = 813 + $4000
    Symbol T2400 = 396
    Symbol N2400 = 396 + $4000
    Symbol T4800 = 188
    Symbol N4800 = 188 + $4000
    Symbol T9600 = 84
    Symbol N9600 = 84 + $4000

    Symbol OT2400 = 396 + $8000                    ' Open True
    Symbol OT1200 = 813 + $8000                    ' Open True
    Symbol OT9600 = 84 + $8000                      ' Open True
    Symbol OT300 = 3313 + $8000                    ' Open True

    Symbol ON2400 = 396 + $4000 + $8000            ' Open Inverted
    Symbol ON1200 = 813 + $4000 + $8000            ' Open Inverted
    Symbol ON9600 = 84 + $4000 + $8000              ' Open Inverted
    Symbol ON300 = 3313 + $4000 + $8000            ' Open Inverted

broderic

Thank you Les, but I don't still understand.
On page 248 of the manual is written that to run with 9600 baudrate "8-bit no-parity inverted", since I'm using MAX232, I need a baumode argument of 16468.
But if I use this value it doesn't work. It works if I put 84, that is for not inverted (true).
It seems as the 2 colums at the bottom of page 248 are exchanged...
Why do I need a value in the column "true" to run a hardware that is working in inverted mode?
Thanks again.
Regards

top204

#3
Remember, the MAX232 inverts the data to it, so that may be your problem.

As a test, below is the code for Inverted serial data using the Serin and Serout commands at 9600 Baud:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Receive and Transmit inverted serial data at 9600 Baud using the Serin/Serout commands
' Written for the Positron8 compiler by Les Johnson
'
    Device = 16F876                             ' Tell the compiler what device is being compiled for
    Declare Xtal = 10                           ' Tell the compiler what speed the device will be operating at
'
' Create a byte variable
'
    Dim MyByte As Byte
'
' Create constants
'
    Symbol T9600 = 84                           ' The value for Serin/Serout for non-inverted 9600 Baud
    Symbol N9600 = 84 + $4000                   ' The value for Serin/Serout for inverted 9600 Baud
   
'---------------------------------------------------
' The main program starts here
' Re-Transmit the character that is received
'
Main:   
    Do                                          ' Create a loop
        SerIn PORTB.1, N9600, [MyByte]          ' Receive inverted data at 9600 Baud into MyByte
        SerOut PORTB.0, N9600, [MyByte]         ' Transmit MyByte inverted at 9600 Baud
    Loop                                        ' Do it forever

And below is the simulator running the above program, with the letters typed into the Terminal set for 9600 inverted coms:
Inverted.jpg

The program below is the same flow as the previous program, but uses non-inverted serial coms at 9600 Baud:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Receive and Transmit non-inverted serial data at 9600 Baud using the Serin/Serout commands
' Written for the Positron8 compiler by Les Johnson
'
    Device = 16F876                             ' Tell the compiler what device is being compiled for
    Declare Xtal = 10                           ' Tell the compiler what speed the device will be operating at
'
' Create a byte variable
'
    Dim MyByte As Byte
'
' Create constants
'
    Symbol T9600 = 84                           ' The value for Serin/Serout for non-inverted 9600 Baud
    Symbol N9600 = 84 + $4000                   ' The value for Serin/Serout for inverted 9600 Baud
   
'---------------------------------------------------
' The main program starts here
' Re-Transmit the character that is received
'
Main:   
    Do                                          ' Create a loop
        SerIn PORTB.1, T9600, [MyByte]          ' Receive non-inverted data at 9600 Baud into MyByte
        SerOut PORTB.0, T9600, [MyByte]         ' Transmit MyByte non-inverted at 9600 Baud
    Loop                                        ' Do it forever

And the simulator is now running the above program with its Terminal set for non-inverted (True) coms:

Non-Inverted.jpg

Also notice, the high resistance pull-up or pull-down resistor on the RX line of the terminals, so the pin is not floating. The polarity of it depends on inverted or non-inverted coms, and is an important circuit addition to all RX lines, otherwise, the Start bit is not fully detected and timeouts will be random.

broderic

Hello Les.
A lot of thanks for your kind and exhaustive explanation and for the time you spent.
Enclose is my hardware circuit (Easypic V7)
RS232 circuit.JPG

It has Max232.
The working properly code is this one:

 Device = 16F876A                            ' Tell the compiler what device is being compiled for
    Declare Xtal = 10                        ' Tell the compiler what speed the device will be operating at
'
' Create a byte variable
'
    Dim MyByte As Byte
'
' Create constants
'
    Symbol T9600 = 84                          ' The value for Serin/Serout for non-inverted 9600 Baud
    Symbol N9600 = 84 + $4000                  ' The value for Serin/Serout for inverted 9600 Baud
   
'---------------------------------------------------
' The main program starts here
' Re-Transmit the character that is received
'
Main:   
  For MyByte = 0 To 9  Step 1
 SerOut PORTC.6,T9600,["Mybyte: ",Dec MyByte,13]
 Next


This code is with non-inverting parameter T9600.
But since the hardware is with MAX232, it should need instead "inverted" parameter, shouldn't it?

Thanks again and sorry for my "dummy" understanding.

Yasin

No. In RS232 hardware, if there is a high level on the TTL side, it means there is a negative (ie - 8...-12V) level on the RS232 side. If there is a low level on the TTL side, it means there is a positive (ie + 8...+12V) level on the RS232 side.

Stephen Moss

Quote from: broderic on Feb 01, 2022, 08:52 AMBut since the hardware is with MAX232, it should need instead "inverted" parameter, shouldn't it?
Ideally there would be a MAX232 or equivalent at both ends, the transmitting 232 inverts and changes the voltage from 5V to 12V?, the receiver then reverse that.
So providing there is a MAX232 or equivalent at each end of the cable the data sent should be exactly what you want to send and will be received out of the 2323 at the receiving exactly as it was sent.
The inversion & voltage change is to enable transmission between the two 232's, but is completly transparent to the sending and receiving devices as though the MAX232 were never there.   

broderic

Thank you, Yasin.
Thank you Stephen.Stephen, your comment helped me a lot in removing the clouds in my minds.
What I missed is probably that there's a second 232 converter inside the PC input area (see enclosure), that inverts again the signal.
That's why I need the True option as Les explained to me.

The transmission properly works with True option, with the LED RC6, RC7 light on on Easypic V7.

What made me out of way is that I have the right behaviour both with Positron instruction:
 
SerOut PORTC.6,T9600,["Mybyte: ",Dec MyByte,13]---------> True

and with MBasic instruction:

SerOut PORTC.6,I8N1_9600,["Mybyte: ",Dec MyByte,13]-----> Inverted.

Mmmm...remains for me still not well understood (maybe compiler specific...?)

Thank you again for your kind attention.

Regards