The software serial routines are for sending byte size data. Although you might expect the low byte to be transmitted in this case, so recheck your hardware. Is Pic Tx connected to max232 Rx, common grounds, etc. Might try different baud rate, failing that, there has been plenty of past discussion on this subject.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think the RS232.h file is in need of an overhaul. The timing just doesn't seem to calculate?, and there's no ascii conversion. If using r24000, try commenting out the SerBitDelay sub in the SerTxHigh/SerTxLow subs. In its place, put your delay in (417 us) say "wait 42 10us", or try "wait 41 10us".
You are changing your binary data to ascii, right? Probably going to take less code if you send out the data in two bytes like:
....
dim Messwert as Word
....
First off, you need to establish contact with hyperterminal. So try and use the suggested fix for rs232.h to do just that. Also for baud of 2300, a "wait 417 us" in place of the SerBitDelay sub, GCBasic will handle that as long its a constant. Any sort of gibberish in hyperterminal is o.k. to start with.
Still doesn't work?, then try the alternative software serial routine. You may have to try a baud rate thats plus/minus a tick or two. Using this at 9600 baud appeared sketchy to me on a 16f877a with a "4mhz" internal osc.
Once contact is established you could then add the provided code, or some other variation to properly transfer the variables and characters. Suggest looking up wikipedia or google about for ascii characters and tables. Want to print strings?, then add something like:
...
XMIT_Print ("Hello")
...
sub XMIT_Print (PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
'Write Data
for SysPrintTemp = 1 to PrintLen
XMIT_RS232(PrintData(SysPrintTemp))
next
end sub
'Alternative Software serial routine
'Must supply the correct baud rate, etc. in the Ser_Init sub
'Add Bin2ascii and XMIT_Print subs for complete solution
Ser_Init
....
start:
test = 75
XMIT_RS232(test)
goto start
...
Sub Ser_Init
#define baud 104 ;the us delay for 9600 baud rate
#define SerTxHigh Set PortD.1 On
#define SerTxLow Set PortD.1 Off
dir PortD.1 out
SerTxHigh ;Initial RS232 idle state
end sub
sub XMIT_PRINT (PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
'Write Data
for SysPrintTemp = 1 to PrintLen
XMIT_RS232(PrintData(SysPrintTemp))
next
end sub
Sub XMIT_RS232(Xmit_Byte)#NR
SerTxLow ;Start bit
wait baud us
For cntr = 1 to 8
Rotate Xmit_Byte Right
If Status.C ON Then SerTxHigh
If Status.C Off Then SerTxLow
wait baud us
Next
SerTxHigh ;Stop bit
wait baud us
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Further explanation on the XMIT_RS232 sub, was used on a serial lcd, so no parity was used, and there was no data inversion. If you were to use that with a max232 then data inversion would need to be added (i.e. swap SerTxHigh and SerTxLow).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
start:
test = ReadAD10(AN1)
XMIT_RS232(test)
goto start
Sub Ser_Init
#define baud 417 ;the us delay for 2400 baud rate
#define SerTxHigh Set GPIO.1 off
#define SerTxLow Set GPIO.1 On
dir GPIO.1 out
dir GPIO.0 in
SerTxHigh ;Initial RS232 idle state
end sub
sub XMIT_PRINT (PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
'Write Data
for SysPrintTemp = 1 to PrintLen
XMIT_RS232(PrintData(SysPrintTemp))
next
end sub
Sub XMIT_RS232(Xmit_Byte)#NR
SerTxLow ;Start bit
wait baud us
For cntr = 1 to 8
Rotate Xmit_Byte Right
If Status.C ON Then SerTxHigh
If Status.C Off Then SerTxLow
wait baud us
Next
SerTxHigh ;Stop bit
wait baud us
end sub
I get gibberish in hyperTerminal, So now what do I change to get my a/d reading sent in ascii, i get i need to add the bin2ascii rooutine,here is what I tried:
#chip 12F675, 4 'mhz
#config OSC=INTOSC, MCLRE=off, WDT=off
#mem 128 'Chip has 128 bytes
EEADRH = 0
Sub Ser_Init
#define baud 417 ;the us delay for 2400 baud rate
#define SerTxHigh Set GPIO.1 off
#define SerTxLow Set GPIO.1 On
dir GPIO.1 out
dir GPIO.0 in
SerTxHigh ;Initial RS232 idle state
end sub
sub XMIT_PRINT (PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
'Write Data
for SysPrintTemp = 1 to PrintLen
XMIT_RS232(PrintData(SysPrintTemp))
next
end sub
Sub XMIT_RS232(Xmit_Byte)#NR
SerTxLow ;Start bit
wait baud us
For cntr = 1 to 8
Rotate Xmit_Byte Right
If Status.C ON Then SerTxHigh
If Status.C Off Then SerTxLow
wait baud us
Next
SerTxHigh ;Stop bit
wait baud us
end sub
sub Bin2ascii(LCDValue )#NR
SERCEN = 0
SERDEC = 0
SERUN = 0
LCDValueTemp = 0
If LCDValue >= 100 Then
LCDValueTemp = LCDValue / 100
SERCEN = LCDValueTemp + 48
SerSend (1,SERCEN)
LCDValue = LCDValue - LCDValueTemp * 100
end if
IF LCDValueTemp > 0 OR LCDValue >= 10 then
LCDValueTemp = LCDValue / 10
SERDEC = LCDValueTemp + 48
SerSend (1,SERDEC)
LCDValue = LCDValue - LCDValueTemp * 10
end if
SERUN = LCDValue + 48
SerSend (1,SERUN)
end sub
But it does not send anything to hyperterminal?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
No on the second example, because need to replace "SerSend(1,SerCen)" with "Xmit_RS232(SerCen)".... etc. in the BIN2ascii sub. Also, declare correct analog channel as an input prior to Start/Main. The SerTxHigh/SerTxLow and AN1 are using the same GPIO.1 pin in the code, keep them seperate.
No idea how you are handling the temp sensor, but for arguments sake this is a Uart question, so just try a known quantity first and save any temp problems for a seperate post. Add a delay, otherwise the numbers will be coming too fast.
The "mem 128" command no longer required. You can drop the EEADRH = 0, if you stick with the XMIT_RS232 sub. Don't forget to try +/- values for baud, if 417 doesn't work.
start:
for test = 1 to 10
Bin2Ascii(test)
Wait 3 s
Next
goto start
If you get that to work, then the a-d might go like:
start:
AD1 = ReadAD10(AN1)
Bin2ascii (AD1_H)
Bin2ascii (AD1)
wait 3 s
goto start
Never hurts to comment things if you have to come back later.
#define SerTxHigh Set GPIO.1 off 'inverted off, normal On
#define SerTxLow Set GPIO.1 On 'inverted On, normal off
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sub Ser_Init
#define baud 417 ;the us delay for 2400 baud rate
#define SerTxHigh Set GPIO.1 off
#define SerTxLow Set GPIO.1 On
dir GPIO.1 out
dir GPIO.0 in
SerTxHigh ;Initial RS232 idle state
end sub
sub XMIT_PRINT (PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
'Write Data
for SysPrintTemp = 1 to PrintLen
XMIT_RS232(PrintData(SysPrintTemp))
next
end sub
Sub XMIT_RS232(Xmit_Byte)#NR
SerTxLow ;Start bit
wait baud us
For cntr = 1 to 8
Rotate Xmit_Byte Right
If Status.C ON Then SerTxHigh
If Status.C Off Then SerTxLow
wait baud us
Next
SerTxHigh ;Stop bit
wait baud us
end sub
sub Bin2ascii(LCDValue )#NR
SERCEN = 0
SERDEC = 0
SERUN = 0
LCDValueTemp = 0
If LCDValue >= 100 Then
LCDValueTemp = LCDValue / 100
SERCEN = LCDValueTemp + 48
Xmit_RS232(SerCen) 'SerSend (1,SERCEN)
LCDValue = LCDValue - LCDValueTemp * 100
end if
IF LCDValueTemp > 0 OR LCDValue >= 10 then
LCDValueTemp = LCDValue / 10
SERDEC = LCDValueTemp + 48
Xmit_RS232(Serdec) 'SerSend (1,SERDEC)
LCDValue = LCDValue - LCDValueTemp * 10
end if
SERUN = LCDValue + 48
Xmit_RS232(Serun) 'SerSend (1,SERUN)
end sub
I'm getting communication, but nothing legible, the sensor I'm using outputs the temp/100 in voltage so that 75 degrees=.75vdc, 100degrees=1.00vdc linearly.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For anyone reviewing this post further down the line. The fact is (after testing once again), no inverting is required for the Xmit_RS232 routine. The ser_init was correctly stated at the first posting, i.e.:
#define SerTxHigh Set PortD.1 On
#define SerTxLow Set PortD.1 Off
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ive used the 12F675 and the Software uart with success, but there are problems in
using the Internal Oscillator unless you calibrate it.
Its much easier to use an external crystal.
Calibrating the Internal Oscillator requires some kind of frequency counter
and you need to measure the clock out , and then write a value for the Osccal byte
to shift the Internal clock to 4 MHZ.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If the software UART function is properly implemented at the compiler level, the internal oscillator should provide reliable operation up to at least 9600 baud. I say this because my company has tens of thousands of devices operating in the field, at extreme environments, for over 5 years using PicBasis Pro's software UART with internal oscillator. This is with no factory calibration of the oscillator.
In my experience, reliability begins to fall off if you go much higher than 9600, probably because of the inability of the software system to accurately resolve short pulse widths with a low frequency (4MHz) system clock.
I said "properly coded" above'; I don't know how efficiently coded GCBasic's UART implementation actually is, but I do from experience with at least one other compiler that the internal oscillator isn't necessarily the limiting factor, at least at 9600 baud and below.
Joe
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
here is part of my code, ran into a max232, I cannot get it to send anything serially?
#chip 12F675, 4
dir GPIO.0 out 'serial out
dir GPIO.1 in 'temp sensor
InitSer (1, r2400, 1, 8, 1, none, invert)
#define SendAHigh Set GPIO.0 ON
#define SendALow Set GIO.0 OFF
start:
SerSend 1, ReadAD10(AN1)
wait 5 s
goto start
The software serial routines are for sending byte size data. Although you might expect the low byte to be transmitted in this case, so recheck your hardware. Is Pic Tx connected to max232 Rx, common grounds, etc. Might try different baud rate, failing that, there has been plenty of past discussion on this subject.
I tried many baud rates, all connection good same ground.
Code:
#chip 12F675, 4 'mhz
#config OSC=INTOSC, MCLRE=off, WDT=off
#define SendAHigh Set GPIO.1 ON
#define SendALow Set GPIO.1 OFF
dir GPIO.0 in
dir GPIO.1 out
InitSer(1,r2400,1,8,1,none,invert)
start:
Messwert=ReadAD10(AN0)
SerSend(1, Messwert)
Wait 2 s
goto start
I cant' get anything on hyperterminal?
Is there something missing in my code?
I think the RS232.h file is in need of an overhaul. The timing just doesn't seem to calculate?, and there's no ascii conversion. If using r24000, try commenting out the SerBitDelay sub in the SerTxHigh/SerTxLow subs. In its place, put your delay in (417 us) say "wait 42 10us", or try "wait 41 10us".
You are changing your binary data to ascii, right? Probably going to take less code if you send out the data in two bytes like:
....
dim Messwert as Word
....
start:
....
Bin2ascii(Messwert_H)
Bin2ascii(Messwert)
....
goto start
sub Bin2ascii(LCDValue )#NR
SERCEN = 0
SERDEC = 0
SERUN = 0
LCDValueTemp = 0
If LCDValue >= 100 Then
LCDValueTemp = LCDValue / 100
SERCEN = LCDValueTemp + 48
SerSend (1,SERCEN)
LCDValue = LCDValue - LCDValueTemp * 100
end if
IF LCDValueTemp > 0 OR LCDValue >= 10 then
LCDValueTemp = LCDValue / 10
SERDEC = LCDValueTemp + 48
SerSend (1,SERDEC)
LCDValue = LCDValue - LCDValueTemp * 10
end if
SERUN = LCDValue + 48
SerSend (1,SERUN)
end sub
So I add these line to my code?
First off, you need to establish contact with hyperterminal. So try and use the suggested fix for rs232.h to do just that. Also for baud of 2300, a "wait 417 us" in place of the SerBitDelay sub, GCBasic will handle that as long its a constant. Any sort of gibberish in hyperterminal is o.k. to start with.
Still doesn't work?, then try the alternative software serial routine. You may have to try a baud rate thats plus/minus a tick or two. Using this at 9600 baud appeared sketchy to me on a 16f877a with a "4mhz" internal osc.
Once contact is established you could then add the provided code, or some other variation to properly transfer the variables and characters. Suggest looking up wikipedia or google about for ascii characters and tables. Want to print strings?, then add something like:
...
XMIT_Print ("Hello")
...
sub XMIT_Print (PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
'Write Data
for SysPrintTemp = 1 to PrintLen
XMIT_RS232(PrintData(SysPrintTemp))
next
end sub
'Alternative Software serial routine
'Must supply the correct baud rate, etc. in the Ser_Init sub
'Add Bin2ascii and XMIT_Print subs for complete solution
Ser_Init
....
start:
test = 75
XMIT_RS232(test)
goto start
...
Sub Ser_Init
#define baud 104 ;the us delay for 9600 baud rate
#define SerTxHigh Set PortD.1 On
#define SerTxLow Set PortD.1 Off
dir PortD.1 out
SerTxHigh ;Initial RS232 idle state
end sub
sub XMIT_PRINT (PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
'Write Data
for SysPrintTemp = 1 to PrintLen
XMIT_RS232(PrintData(SysPrintTemp))
next
end sub
Sub XMIT_RS232(Xmit_Byte)#NR
SerTxLow ;Start bit
wait baud us
For cntr = 1 to 8
Rotate Xmit_Byte Right
If Status.C ON Then SerTxHigh
If Status.C Off Then SerTxLow
wait baud us
Next
SerTxHigh ;Stop bit
wait baud us
end sub
Further explanation on the XMIT_RS232 sub, was used on a serial lcd, so no parity was used, and there was no data inversion. If you were to use that with a max232 then data inversion would need to be added (i.e. swap SerTxHigh and SerTxLow).
Ok using this:
#chip 12F675, 4 'mhz
#config OSC=INTOSC, MCLRE=off, WDT=off
#mem 128 'Chip has 128 bytes
EEADRH = 0
Ser_Init
start:
test = ReadAD10(AN1)
XMIT_RS232(test)
goto start
Sub Ser_Init
#define baud 417 ;the us delay for 2400 baud rate
#define SerTxHigh Set GPIO.1 off
#define SerTxLow Set GPIO.1 On
dir GPIO.1 out
dir GPIO.0 in
SerTxHigh ;Initial RS232 idle state
end sub
sub XMIT_PRINT (PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
'Write Data
for SysPrintTemp = 1 to PrintLen
XMIT_RS232(PrintData(SysPrintTemp))
next
end sub
Sub XMIT_RS232(Xmit_Byte)#NR
SerTxLow ;Start bit
wait baud us
For cntr = 1 to 8
Rotate Xmit_Byte Right
If Status.C ON Then SerTxHigh
If Status.C Off Then SerTxLow
wait baud us
Next
SerTxHigh ;Stop bit
wait baud us
end sub
I get gibberish in hyperTerminal, So now what do I change to get my a/d reading sent in ascii, i get i need to add the bin2ascii rooutine,here is what I tried:
#chip 12F675, 4 'mhz
#config OSC=INTOSC, MCLRE=off, WDT=off
#mem 128 'Chip has 128 bytes
EEADRH = 0
dim AD1 as Word
Ser_Init
start:
Bin2ascii (AD1_H)
Bin2ascii (AD1)
AD1 = ReadAD10(AN1)
XMIT_RS232(AD1)
goto start
Sub Ser_Init
#define baud 417 ;the us delay for 2400 baud rate
#define SerTxHigh Set GPIO.1 off
#define SerTxLow Set GPIO.1 On
dir GPIO.1 out
dir GPIO.0 in
SerTxHigh ;Initial RS232 idle state
end sub
sub XMIT_PRINT (PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
'Write Data
for SysPrintTemp = 1 to PrintLen
XMIT_RS232(PrintData(SysPrintTemp))
next
end sub
Sub XMIT_RS232(Xmit_Byte)#NR
SerTxLow ;Start bit
wait baud us
For cntr = 1 to 8
Rotate Xmit_Byte Right
If Status.C ON Then SerTxHigh
If Status.C Off Then SerTxLow
wait baud us
Next
SerTxHigh ;Stop bit
wait baud us
end sub
sub Bin2ascii(LCDValue )#NR
SERCEN = 0
SERDEC = 0
SERUN = 0
LCDValueTemp = 0
If LCDValue >= 100 Then
LCDValueTemp = LCDValue / 100
SERCEN = LCDValueTemp + 48
SerSend (1,SERCEN)
LCDValue = LCDValue - LCDValueTemp * 100
end if
IF LCDValueTemp > 0 OR LCDValue >= 10 then
LCDValueTemp = LCDValue / 10
SERDEC = LCDValueTemp + 48
SerSend (1,SERDEC)
LCDValue = LCDValue - LCDValueTemp * 10
end if
SERUN = LCDValue + 48
SerSend (1,SERUN)
end sub
But it does not send anything to hyperterminal?
Gibberish is good, getting close I hope.
No on the second example, because need to replace "SerSend(1,SerCen)" with "Xmit_RS232(SerCen)".... etc. in the BIN2ascii sub. Also, declare correct analog channel as an input prior to Start/Main. The SerTxHigh/SerTxLow and AN1 are using the same GPIO.1 pin in the code, keep them seperate.
No idea how you are handling the temp sensor, but for arguments sake this is a Uart question, so just try a known quantity first and save any temp problems for a seperate post. Add a delay, otherwise the numbers will be coming too fast.
The "mem 128" command no longer required. You can drop the EEADRH = 0, if you stick with the XMIT_RS232 sub. Don't forget to try +/- values for baud, if 417 doesn't work.
start:
for test = 1 to 10
Bin2Ascii(test)
Wait 3 s
Next
goto start
If you get that to work, then the a-d might go like:
start:
AD1 = ReadAD10(AN1)
Bin2ascii (AD1_H)
Bin2ascii (AD1)
wait 3 s
goto start
Never hurts to comment things if you have to come back later.
#define SerTxHigh Set GPIO.1 off 'inverted off, normal On
#define SerTxLow Set GPIO.1 On 'inverted On, normal off
Okay with this:
#chip 12F675, 4 'mhz
#config OSC=INTOSC, MCLRE=off, WDT=off
'#mem 128 'Chip has 128 bytes
'EEADRH = 0
Ser_Init
dim test as Word
start:
test = ReadAD10(AN0)
Bin2ascii (test_H)
Bin2ascii (test)
XMIT_RS232(test)
wait 2 sec
goto start
Sub Ser_Init
#define baud 417 ;the us delay for 2400 baud rate
#define SerTxHigh Set GPIO.1 off
#define SerTxLow Set GPIO.1 On
dir GPIO.1 out
dir GPIO.0 in
SerTxHigh ;Initial RS232 idle state
end sub
sub XMIT_PRINT (PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
'Write Data
for SysPrintTemp = 1 to PrintLen
XMIT_RS232(PrintData(SysPrintTemp))
next
end sub
Sub XMIT_RS232(Xmit_Byte)#NR
SerTxLow ;Start bit
wait baud us
For cntr = 1 to 8
Rotate Xmit_Byte Right
If Status.C ON Then SerTxHigh
If Status.C Off Then SerTxLow
wait baud us
Next
SerTxHigh ;Stop bit
wait baud us
end sub
sub Bin2ascii(LCDValue )#NR
SERCEN = 0
SERDEC = 0
SERUN = 0
LCDValueTemp = 0
If LCDValue >= 100 Then
LCDValueTemp = LCDValue / 100
SERCEN = LCDValueTemp + 48
Xmit_RS232(SerCen) 'SerSend (1,SERCEN)
LCDValue = LCDValue - LCDValueTemp * 100
end if
IF LCDValueTemp > 0 OR LCDValue >= 10 then
LCDValueTemp = LCDValue / 10
SERDEC = LCDValueTemp + 48
Xmit_RS232(Serdec) 'SerSend (1,SERDEC)
LCDValue = LCDValue - LCDValueTemp * 10
end if
SERUN = LCDValue + 48
Xmit_RS232(Serun) 'SerSend (1,SERUN)
end sub
I'm getting communication, but nothing legible, the sensor I'm using outputs the temp/100 in voltage so that 75 degrees=.75vdc, 100degrees=1.00vdc linearly.
For anyone reviewing this post further down the line. The fact is (after testing once again), no inverting is required for the Xmit_RS232 routine. The ser_init was correctly stated at the first posting, i.e.:
#define SerTxHigh Set PortD.1 On
#define SerTxLow Set PortD.1 Off
that was because i was useing a max232 chip, though
Ive used the 12F675 and the Software uart with success, but there are problems in
using the Internal Oscillator unless you calibrate it.
Its much easier to use an external crystal.
Calibrating the Internal Oscillator requires some kind of frequency counter
and you need to measure the clock out , and then write a value for the Osccal byte
to shift the Internal clock to 4 MHZ.
If the software UART function is properly implemented at the compiler level, the internal oscillator should provide reliable operation up to at least 9600 baud. I say this because my company has tens of thousands of devices operating in the field, at extreme environments, for over 5 years using PicBasis Pro's software UART with internal oscillator. This is with no factory calibration of the oscillator.
In my experience, reliability begins to fall off if you go much higher than 9600, probably because of the inability of the software system to accurately resolve short pulse widths with a low frequency (4MHz) system clock.
I said "properly coded" above'; I don't know how efficiently coded GCBasic's UART implementation actually is, but I do from experience with at least one other compiler that the internal oscillator isn't necessarily the limiting factor, at least at 9600 baud and below.
Joe