Windows, PIC16F628A with INT OSC, PIC on Prolific-USB-Serial-Com, GCBASIC 0.9
I perfectly receive the 7 first bit (*)but can't get the last one … I tried all possible InitSer values as well as on the Windows side.
(*) I always receive half the expected value
The RS232 hardware works perfectly, up to 19200 with the 4MHz INT OSC of a 16F628A (osc freq measured 98.5%)
More on request
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
RS232 Software TX has one BIG bug at least.
The sleep, idle, no signal state of an RS232 TX line is ON / 1 / Vdd
The Start Bit is à 0
The Stop Bit is a 1
GCBASIC RS232 Software is all wrong on these
This can be solved by changing two lines in rs232.h
line 157 : start bit
SerTxLow ' instead of SerTxHigh
line 184 : stop bit
SerTxHigh ' instead of SerTxLow
With these two changes, my PC receives correctly my PIC16F628A with it's internal 4MHz clock up to 4800 baud, on an USB RS232 TTL using prolific
It must be the same on RX side ???? …
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Many rs232 devices invert the logic signals during level conversion through a rs232 driver chip.
This can cause much frustration and confusion to beginners.
It looks like a bug but is really just the way the hardware works.
Here is what is required to make the rs232 low level code work with inverted logic levels.
your original code is here along with workaround in bold type:
#define SendAHigh Set PORTB.2 ONchange to OFF
#define SendALow Set PORTB.2 OFFchange to ON
#define RecAHigh PORTB.1 ON change to OFF
#define RecALow PORTB.1 OFFchange to ON
InitSer 1, r2400, 1+WaitForStart, 8, 1, none, normalchange to invert
I am using this method for many, many projects with 100% success.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for GCBASIC,
Windows, PIC16F628A with INT OSC, PIC on Prolific-USB-Serial-Com, GCBASIC 0.9
I perfectly receive the 7 first bit (*)but can't get the last one … I tried all possible InitSer values as well as on the Windows side.
(*) I always receive half the expected value
The RS232 hardware works perfectly, up to 19200 with the 4MHz INT OSC of a 16F628A (osc freq measured 98.5%)
More on request
Hi,
Please post your serial port configuration code in your GCBASIC program.
I have run into similar problems. It will be easier to explain after viewing your code.
There are two bugs in the soft RS232 routines .
First bug is that the soft routines only work properly at 20 MHz on the PIC family. Try a 20MHZ crystal.
Second bug is that the calculation for 19200 baud rate is faulty.
open the gcbasic\include\lowlevel folder
open the file 'rs232.h'
find this line
SerThirdDelay19200 = int(17 - 4 / ChipMHz * 35)
change 17 to 19
Use 9600 for testing for the moment.
With GCBASIC RS232 Software :
InitSer 1, r2400, 1+WaitForStart, 8, 1, none, normal
I tried with :
InitSer 1, r2400, 0, 8, 1, none, normal
InitSer 1, r2400, 1, 8, 1, none, normal
InitSer 1, r2400, 129, 8, 1, none, normal
InitSer 1, r2400, 2, 8, 1, none, normal
When two PICs communicate with GCBASIC RS232 Software it works perfectly up to 4800 bauds
I noticed one difference between Soft and Hardware RS232, the waiting output is OFF in software and ON in Hardware RS232 ???
Not yet tested with 9600 and 20 MHz … you deserve an answer first :-)
In next message, I'll post my code
<code>
' ==============================================================
' PIC 16F628A RS232 SOFTWARE TX CODE March 1st, 2013
' Only 7 bit are received
'
' ==============================================================
#chip 16F628A, 4
#config MCLR_OFF
'
' - Init TX -
' -------
#define SendAHigh Set PORTB.2 ON
#define SendALow Set PORTB.2 OFF
'
Dir PORTB.2 Out
'
' - Init RX -
' --------
#define RecAHigh PORTB.1 ON
#define RecALow PORTB.1 OFF
'
' ==============================================================
' --- Transmitter ---
' --------------
DataTransmitter:
'
InitSer 1, r2400, 1+WaitForStart, 8, 1, none, normal
'
Do
If Temp = 100 Then
Temp = 50
Else
Temp = 100
End If
SerSend 1, Temp
Wait 20 10ms
Loop
'
</code>
FreeBasic RX code
<code>
' =========================================================
' START FREEBASIC RX CODE
' #include once "windows.bi"
' '
' Dim As Integer iCom, iFile, iCount = 0
' Dim sCom As String
' iFile = FreeFile
' '
' sCom = "COM6:2400,N,8,1,cs0,ds0,cd0,rs"
' ' Open Com sCom As iFile
' iCom = Open Com (sCom, As iFile)
' If iCom = 0 Then
' Print "OPEN COM OK Returns 0"
' Else
' MessageBox (0, "ERROR OPEN COM FAILED, I CLOSE", "GCBASIC RS232 RX TEST", 0)
' End
' End If
' '
' Dim bData As uByte
' '
' bData = 0
' Messagebox (0, "CLOSE TO START RS232 RX", "Jack", 0)
' '
' iCount = 0
' Get #iFile, , bData
' While icount < 20
' If bData <> 0 Then
' Print bData
' iCount = iCount + 1
' End If
' bdata = 0
' Sleep 10
' Get #iFile, , bData
' Wend
' Print
'
' Print " **** FINISHED ****"
' '
' Close iFile
' Sleep
' END FREEBASIC RX CODE
' =========================================================
</code>
Quartz 20 MHz, baud rate 9600, RS232 Software same problem : I receive half the sent value
SOLVED
http://fr.wikipedia.org/wiki/UART (in french, the english version is different and less clear)
RS232 Software TX has one BIG bug at least.
The sleep, idle, no signal state of an RS232 TX line is ON / 1 / Vdd
The Start Bit is à 0
The Stop Bit is a 1
GCBASIC RS232 Software is all wrong on these
This can be solved by changing two lines in rs232.h
line 157 : start bit
SerTxLow ' instead of SerTxHigh
line 184 : stop bit
SerTxHigh ' instead of SerTxLow
With these two changes, my PC receives correctly my PIC16F628A with it's internal 4MHz clock up to 4800 baud, on an USB RS232 TTL using prolific
It must be the same on RX side ???? …
Hi,
Many rs232 devices invert the logic signals during level conversion through a rs232 driver chip.
This can cause much frustration and confusion to beginners.
It looks like a bug but is really just the way the hardware works.
Here is what is required to make the rs232 low level code work with inverted logic levels.
your original code is here along with workaround in bold type:
#define SendAHigh Set PORTB.2
ONchange to OFF#define SendALow Set PORTB.2
OFFchange to ON#define RecAHigh PORTB.1
ONchange to OFF#define RecALow PORTB.1
OFFchange to ONInitSer 1, r2400, 1+WaitForStart, 8, 1, none,
normalchange to invertI am using this method for many, many projects with 100% success.