dual uart asmbler directive _bank (I think it's a directive)
bdrury@polycon.on.ca
Posts: 2
Just learning SX28 and assembler would apreciate some help:
Problem #1
The dual uart virtual peripheral download from the Parallax site·on page 5 has the following
code
_bank···· Multiplexbank· ;
inc········ isrMultiplex·····; toggle interrupt rate
mov······ w,isrMultipelx· ;
What does the uderscore do, is this actually just a bank command ?
Problem #2
Is there some more info on the following definitions used on Page 3 of the above download
UARTfs = 230400 (where did this come from)
Num = 4· (I think I understand this one apears every fourth interupt this thread is run)
Int Period =217· (I think understand I this one interupt is every 217 clock cycles aprox instructions)
Uart1 baud rate definition
UARTDivide1 = UARTfs/(UARTbaud1*Num)
(now· I am confused I think this is number of time isrThread1 must be called to generate bit time)
UARTStDelay1=UARTDivide1 + (UARTDivide1/2)+1 (I think this is sample at middle of bit time)
Uart2 baud rate definition ( this will be same thing as for Uart1 applied to Uart2)
UARTDivide2 = UARTfs/(UARTbaud2*Num)
UARTStDelay2=UARTDivide2 + (UARTDivide12/2)+1
·What·I want to do is set both uarts to 2400 baud 8 data 1 start and 1.5 stop no parity bit
I beleive the above declarations must apear in main code only once to set the baud rate
Thanks for your assistance
Bob Drury
·
Problem #1
The dual uart virtual peripheral download from the Parallax site·on page 5 has the following
code
_bank···· Multiplexbank· ;
inc········ isrMultiplex·····; toggle interrupt rate
mov······ w,isrMultipelx· ;
What does the uderscore do, is this actually just a bank command ?
Problem #2
Is there some more info on the following definitions used on Page 3 of the above download
UARTfs = 230400 (where did this come from)
Num = 4· (I think I understand this one apears every fourth interupt this thread is run)
Int Period =217· (I think understand I this one interupt is every 217 clock cycles aprox instructions)
Uart1 baud rate definition
UARTDivide1 = UARTfs/(UARTbaud1*Num)
(now· I am confused I think this is number of time isrThread1 must be called to generate bit time)
UARTStDelay1=UARTDivide1 + (UARTDivide1/2)+1 (I think this is sample at middle of bit time)
Uart2 baud rate definition ( this will be same thing as for Uart1 applied to Uart2)
UARTDivide2 = UARTfs/(UARTbaud2*Num)
UARTStDelay2=UARTDivide2 + (UARTDivide12/2)+1
·What·I want to do is set both uarts to 2400 baud 8 data 1 start and 1.5 stop no parity bit
I beleive the above declarations must apear in main code only once to set the baud rate
Thanks for your assistance
Bob Drury
·
Comments
Problem #1:
_bank is a marco that is declared somewhere at the beginning of the source code like this:
; For SX18/20/28 change FSR bits 7...5,
; for SX48/52 change FSR bits 6...4
;
_bank macro 1
bank \1
IFDEF SX48_52 ; For SX48/52 change
IF \1 & %10000000 ; FSR bit 7
setb fsr.7
ELSE
clrb fsr.7
ENDIF
ENDIF
endm
It makes sure that FSR bit 7 is correctly set for SX48/52 devices as the bank instruction does not modify bit 7. When you use the SX 28, you don't need the macro, and simply change "_bank" into "bank".
Problem #2:
UARTfs = 230400 is the sample frequency, it defines how often the UART input pins are sampled per second. With a clock frequency of 50 MHz, and an interrupt period of 217, UARTfs is 50 MHz / 217 = 230.4 kHz or 230400 Hz.
Num = 4 - Yes, you are right, this means that the UART code is called every fourth interrupt call.
Int Period = 217 - Yes, this means that the interrupt is fired every 217th clock cycle.
UARTDivide1 = UARTfs/(UARTbaud1*Num) - Yes, this calculates the number of executions of the UART transmit code for one bit length.
UARTStDelay1=UARTDivide1 + (UARTDivide1/2)+1 - After the receiver has detected a start bit, it requires a 1.5 bit time delay to "hit" the first received data bit "in the middle". After the first bit has been read, a delay time of just UARTDivide1 is required to "hit" the next bits "in the middle".
To set the Baud rates to 2400, use the following definitions:
UARTDivide1 = UARTfs/(2400*Num)
UARTDivide2 = UARTfs/(2400*Num)
This would set the UARTS to 2400-8-N-1
BTW: This UART code example is pretty complex - you can find another example in my SX book, and you may download the book code samples from here:
www.parallax.com/Portals/0/Downloads/src/prod/sx/ProgSXEdPre.zip. See TUT40.SRC for the UART example.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
regards
bob drury