Sx uart vp sx/b
Rsadeika
Posts: 3,837
As I was thinking earlier ...
The two pieces of code, the master, and slave, are setup for 9600 baud Tx/Rx, I hope. On the master, the begginings of a VP, on the slave side, just using a serin command. Basically all that I want to do is get master to send the slave an "A" character, for the time being.
The layout for the boards are: using a common ground, both are set for 4MHz internal RC, SX/B with inline assembly. As it stands, does not work as expected, after some testing, I think that on the master side, the ISR is not sending a char out the pin. So, I guess I need some help in trying to figure out how to get the ISR to work properly at 9600 baud @ 4MHz internal RC.
I also want to make sure that, when this is done, I will be able to add, to the ISR, other VP's and have it all run correctly. I am not going to hoarde the code, if I get this thing to work, I will post the working code so other people can learn from my·mistakes. Any suggestions.
Thanks
Ray
*********CODE
This is·the master
'
' Program Description
'
'
' Device Settings
'
DEVICE·SX52,OSC4MHZ
'IRC_CAL IRC_4MHZ
FREQ·4_000_000
'
' IO Pins
'
TX_pin· VAR·RE.7··· ' Transmit pin
'
' Constants
'
ChUp·con 16· 'GoFore
ChDn··· con 17· 'GoBack
Power·· con 21· 'Power (red Button)
'
' Variables
'
tx_high var byte
tx_low var byte
tx_count var byte
tx_divide var byte
txdivisor con 32···· ' Sets the division rate, 32 is for 9600 baud
'
· INTERRUPT NOPRESERVE
'
ISR_Start:
· ASM
'This is the UART transmit
··· test tx_count
··· jz noisr
··· dec tx_divide
··· jnz noisr
··· mov tx_divide,#txdivisor
·· stc
·· rr tx_high
·· rr tx_low
·· dec tx_count
·· movb TX_pin,/tx_low.6
noisr
'End of UART transmit···
· ENDASM
ISR_Exit:
· RETURNINT 104···' 26 uS @ 4 MHz
······························· ' This should be the requirements
······························· ' for 9600 baud
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Subroutine Declarations
'
processCode sub
'
' Program Code
'
Start:
·PLP_A = %00000000········· ' pull-up unused pins
·PLP_B = %00000000
·PLP_C = %00000000
·PLP_D = %00000000
·PLP_E = %00000000
· OPTION = $88·············· ' interrupt, no prescaler
Main:
· processCode
· pause 1000
· GOTO Main
end
'
' Subroutine Code
'
processCode:
'UART transmit
asm
send_byte:
:wait
·· test tx_count
·· jnz :wait
·· mov tx_high,w···· 'Moves char in w to uper byte
·· clrb tx_low.7···· 'So, low byte goes out first, this is inverse (N)
·· mov tx_count,#9·· '1+byte, need stop bit
ret
·· mov tx_divide,#txdivisor
·'· mov !option,#%10011111···· ' Not sure if this is important
·· mov w,#"A"················· ' Send the char "A"
·· call send_byte
endasm
'End of UART transmit
return
**************************************
This is the slave
'
' Program Description
'
'
' Device Settings
'
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
'
' IO Pins
'
·led1 var rc.0
·led2 var rc.1
'
' Constants
'
'
' Variables
'
·rDATA var byte
·temp1 var byte
····························
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Subroutine Declarations
'
·ledon1 sub
·ledon2 sub
'
' Program Code
'
Start:
· PLP_A = %00000000
· PLP_B = %00000000
· PLP_C = %00000000
main:
·do
·· serin rc.7, N9600, rDATA
·loop until rDATA = "A"
'· loop until rDATA > 0
· ledon1
· ledon2
goto main
end
'subs
ledon1:
· low led1
· pause 1000
· high led1
return
ledon2:
· low led2
· pause 1000
· high led2
return
'data
The two pieces of code, the master, and slave, are setup for 9600 baud Tx/Rx, I hope. On the master, the begginings of a VP, on the slave side, just using a serin command. Basically all that I want to do is get master to send the slave an "A" character, for the time being.
The layout for the boards are: using a common ground, both are set for 4MHz internal RC, SX/B with inline assembly. As it stands, does not work as expected, after some testing, I think that on the master side, the ISR is not sending a char out the pin. So, I guess I need some help in trying to figure out how to get the ISR to work properly at 9600 baud @ 4MHz internal RC.
I also want to make sure that, when this is done, I will be able to add, to the ISR, other VP's and have it all run correctly. I am not going to hoarde the code, if I get this thing to work, I will post the working code so other people can learn from my·mistakes. Any suggestions.
Thanks
Ray
*********CODE
This is·the master
'
' Program Description
'
'
' Device Settings
'
DEVICE·SX52,OSC4MHZ
'IRC_CAL IRC_4MHZ
FREQ·4_000_000
'
' IO Pins
'
TX_pin· VAR·RE.7··· ' Transmit pin
'
' Constants
'
ChUp·con 16· 'GoFore
ChDn··· con 17· 'GoBack
Power·· con 21· 'Power (red Button)
'
' Variables
'
tx_high var byte
tx_low var byte
tx_count var byte
tx_divide var byte
txdivisor con 32···· ' Sets the division rate, 32 is for 9600 baud
'
· INTERRUPT NOPRESERVE
'
ISR_Start:
· ASM
'This is the UART transmit
··· test tx_count
··· jz noisr
··· dec tx_divide
··· jnz noisr
··· mov tx_divide,#txdivisor
·· stc
·· rr tx_high
·· rr tx_low
·· dec tx_count
·· movb TX_pin,/tx_low.6
noisr
'End of UART transmit···
· ENDASM
ISR_Exit:
· RETURNINT 104···' 26 uS @ 4 MHz
······························· ' This should be the requirements
······························· ' for 9600 baud
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Subroutine Declarations
'
processCode sub
'
' Program Code
'
Start:
·PLP_A = %00000000········· ' pull-up unused pins
·PLP_B = %00000000
·PLP_C = %00000000
·PLP_D = %00000000
·PLP_E = %00000000
· OPTION = $88·············· ' interrupt, no prescaler
Main:
· processCode
· pause 1000
· GOTO Main
end
'
' Subroutine Code
'
processCode:
'UART transmit
asm
send_byte:
:wait
·· test tx_count
·· jnz :wait
·· mov tx_high,w···· 'Moves char in w to uper byte
·· clrb tx_low.7···· 'So, low byte goes out first, this is inverse (N)
·· mov tx_count,#9·· '1+byte, need stop bit
ret
·· mov tx_divide,#txdivisor
·'· mov !option,#%10011111···· ' Not sure if this is important
·· mov w,#"A"················· ' Send the char "A"
·· call send_byte
endasm
'End of UART transmit
return
**************************************
This is the slave
'
' Program Description
'
'
' Device Settings
'
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
'
' IO Pins
'
·led1 var rc.0
·led2 var rc.1
'
' Constants
'
'
' Variables
'
·rDATA var byte
·temp1 var byte
····························
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Subroutine Declarations
'
·ledon1 sub
·ledon2 sub
'
' Program Code
'
Start:
· PLP_A = %00000000
· PLP_B = %00000000
· PLP_C = %00000000
main:
·do
·· serin rc.7, N9600, rDATA
·loop until rDATA = "A"
'· loop until rDATA > 0
· ledon1
· ledon2
goto main
end
'subs
ledon1:
· low led1
· pause 1000
· high led1
return
ledon2:
· low led2
· pause 1000
· high led2
return
'data
Comments
Parallax and used that instead of the "4MHz internal RC". I remember Jon Williams mentioning
this once somewhere else in this forum a while back.