Stamp not communicating through serial port
joegore
Posts: 6
in BASIC Stamp
I have a Stamp program that polls an Icom amateur radio through its CI-V port (TTL) and reads the operating frequency. When I connect the Stamp directly to the radio through an I/O port, it works just fine.
I now need the program to poll the radio through the serial port on the Stamp Board of Education - I use an RS-232 to TTL level converter to connect to the radio. I have tested the level converter, and it's working as it's supposed to.
I changed my SERIN and SEROUT commands to Pin 16 to use the serial port, but I'm not getting any results - it acts like there is no connection at all. I tried both True and Inverted baudmodes as well.
Maybe I need to do something else besides change the Pin - does anyone have a suggestion?
Thanks ...
Here's my code:
'============================================
' Poll Radio - Display Frequency
' {$STAMP BS2sx}
' {$PBASIC 2.5}
'>>> Seetron OLED display uses PIN 0 <<<
'=================Initialize Display =================
BaudModeInverted CON 16624 '9600, 8N1, Inverted - Seetron OLED
BaudModeTrue CON 240 '9600, 8N1, True
LCDserial CON 0 'Serial Output to Pin 0 for OLED
HIGH LCDserial 'Sets Pin 0 to high for output
PAUSE 100 'Waits for OLED to wake up
SEROUT LCDserial, BaudModeInverted, [$03] 'Sets font to default
SEROUT LCDserial, BaudModeInverted, [$0C] 'Clears screen - cursor top left (Form Feed)
PAUSE 5 'Pause 5ms after each Form Feed ($0C)
'=========================================================================
IcomOutput VAR Byte(11) '11-item array to hold data from radio
GOSUB Main 'Polls radio - gets and displays response
Main:
SEROUT 16, BaudModeTrue,[$FE, $FE, $80, $E0, $03, $FD] 'Request for Frequency (command $03)
'SEROUT 16, BaudModeInverted,[$FE, $FE, $80, $E0, $03, $FD] 'Request for Frequency (command $03)
SERIN 16, BaudModeTrue, [STR IcomOutput\11] 'Array to hold data from radio
'SERIN 16, BaudModeInverted, [STR IcomOutput\11] 'Array to hold data from radio
'Only array values 8, 7 and 6 are used to calculate MHz as an integer - no decimals
'=========================================================================
'Frequency calculations here - based on array values 8, 7 and 6:
Frequency VAR Word
IcomThousands VAR Byte
IcomHundreds VAR Byte
IcomOnes VAR Byte
IcomThousands = IcomOutput(8)
IcomHundreds = IcomOutput(7)
IcomOnes = IcomOutput(6)
'Multiplies digits and adds together for Frequency:
Frequency = (IcomThousands.NIB1 * 10000) + (IcomThousands.NIB0 * 1000) + (IcomHundreds.NIB1 * 100) + (IcomHundreds.NIB0 * 10) + IcomOnes.NIB1
'================================================================================================
SEROUT LCDserial, BaudModeInverted, ["Frequency: ", DEC Frequency] 'Displays Frequency
SEROUT LCDserial, BaudModeInverted, [$0D] 'Carriage Return
PAUSE 1000 'Wait one second between polls
SEROUT LCDserial, BaudModeInverted, [$0C] 'Clears screen - cursor top left (Form Feed)
PAUSE 5 'Pause 5ms after each Form Feed ($0C)
RETURN 'Return to Main program
I now need the program to poll the radio through the serial port on the Stamp Board of Education - I use an RS-232 to TTL level converter to connect to the radio. I have tested the level converter, and it's working as it's supposed to.
I changed my SERIN and SEROUT commands to Pin 16 to use the serial port, but I'm not getting any results - it acts like there is no connection at all. I tried both True and Inverted baudmodes as well.
Maybe I need to do something else besides change the Pin - does anyone have a suggestion?
Thanks ...
Here's my code:
'============================================
' Poll Radio - Display Frequency
' {$STAMP BS2sx}
' {$PBASIC 2.5}
'>>> Seetron OLED display uses PIN 0 <<<
'=================Initialize Display =================
BaudModeInverted CON 16624 '9600, 8N1, Inverted - Seetron OLED
BaudModeTrue CON 240 '9600, 8N1, True
LCDserial CON 0 'Serial Output to Pin 0 for OLED
HIGH LCDserial 'Sets Pin 0 to high for output
PAUSE 100 'Waits for OLED to wake up
SEROUT LCDserial, BaudModeInverted, [$03] 'Sets font to default
SEROUT LCDserial, BaudModeInverted, [$0C] 'Clears screen - cursor top left (Form Feed)
PAUSE 5 'Pause 5ms after each Form Feed ($0C)
'=========================================================================
IcomOutput VAR Byte(11) '11-item array to hold data from radio
GOSUB Main 'Polls radio - gets and displays response
Main:
SEROUT 16, BaudModeTrue,[$FE, $FE, $80, $E0, $03, $FD] 'Request for Frequency (command $03)
'SEROUT 16, BaudModeInverted,[$FE, $FE, $80, $E0, $03, $FD] 'Request for Frequency (command $03)
SERIN 16, BaudModeTrue, [STR IcomOutput\11] 'Array to hold data from radio
'SERIN 16, BaudModeInverted, [STR IcomOutput\11] 'Array to hold data from radio
'Only array values 8, 7 and 6 are used to calculate MHz as an integer - no decimals
'=========================================================================
'Frequency calculations here - based on array values 8, 7 and 6:
Frequency VAR Word
IcomThousands VAR Byte
IcomHundreds VAR Byte
IcomOnes VAR Byte
IcomThousands = IcomOutput(8)
IcomHundreds = IcomOutput(7)
IcomOnes = IcomOutput(6)
'Multiplies digits and adds together for Frequency:
Frequency = (IcomThousands.NIB1 * 10000) + (IcomThousands.NIB0 * 1000) + (IcomHundreds.NIB1 * 100) + (IcomHundreds.NIB0 * 10) + IcomOnes.NIB1
'================================================================================================
SEROUT LCDserial, BaudModeInverted, ["Frequency: ", DEC Frequency] 'Displays Frequency
SEROUT LCDserial, BaudModeInverted, [$0D] 'Carriage Return
PAUSE 1000 'Wait one second between polls
SEROUT LCDserial, BaudModeInverted, [$0C] 'Clears screen - cursor top left (Form Feed)
PAUSE 5 'Pause 5ms after each Form Feed ($0C)
RETURN 'Return to Main program
Comments
Many thanks - I didn't realize the port wasn't really RS-232. That is probably my problem. I've had success with a direct I/O connection, so I'll stick with that ...