Peter Mueller wrote:
Hi,
Am Sonntag, 12.09.04 um 15:57 Uhr schrieb Chris Liechti:
As I wrote playing with the ccr settings was not successful so far.
you cant invert the signal in the hardware, but you can invert the bit
before shifting in: invert the carry bit:
xor #BIT0, r2 ; inverted input
or you can invert the whole byte at the end, which is probably better,
performance wise.
inverting the interrupt edge for the startbit detection should be
trivial too.
chris
Yes I tried this but there seems to be more necessary than just
inverting the tx byte. If I invert the tx byte and want to send a 'H' =
0x48 = 0100 1000b with start and stop bits the following bits are sended:
1 0100 1000 0. The tx signal is low active and I can measure about 1.7ms
for the 4 zeros at 2400 Baud, which is ok.
When inverted the bits I send 0 1011 0111 1. Again I would expect about
1.7ms for the four ones. But now I measure about 2.2 ms.
I assume there is something wrong with the timer a/capture compare
settings which sends a one for some time before the real bits are
shifted out. This is not relevant in the case where tx is low active.
But now, with the inverted signal it is relevant because the high
prolongs my signal.
Any idea what could be wrong?
your code ;-) it's rather difficult to make guesses without seeing any
code.
------------ here is a code fragment i used successfully:
;variables
.data
.comm rxdata,1,1 ;char var
.comm rxshift,1,1 ;char var
.comm rxbit,2,2 ;short var, aligned
.text
interrupt(TIMERA1_VECTOR)
tax_int:
add &TAIV, r0 ; Add TA interrupt offset to PC
reti ; CCR0 - no source
jmp Xccr1 ; CCR1
jmp Xccr2 ; CCR2
reti ; CCR3 - no source
reti ; CCR4 - no source
taover: ; TAOVER (follows directly)
reti
Xccr2: reti ;could be used for something else
;interrupt handler to receive as Timer_A UART
.global ccr1 ;place a label afterwards so
Xccr1: ;that it is used in the listing
add rxbit, r0
jmp .Lrxstart ;start bit
jmp .Lrxdatabit ;D0
jmp .Lrxdatabit ;D1
jmp .Lrxdatabit ;D2
jmp .Lrxdatabit ;D3
jmp .Lrxdatabit ;D4
jmp .Lrxdatabit ;D5
jmp .Lrxdatabit ;D6
; jmp .Lrxlastbit ;D7 that one follows anyway
.Lrxlastbit: ;last bit, handle byte
bit #SCCI, &CCTL1 ;read last bit
xor #BIT0, r2 ; XXX inverted input
rrc.b rxshift ;and save it
clr rxbit ;reset state
mov #CCIE|CAP|CM_1|CCIS_0|SCS, &CCTL1 ;restore cap mode
mov.b rxshift, rxdata ;copy received data
br #swuartrx_interrupt ;call user function, must be an
interrupt function that ends with a reti
.Lrxstart: ;startbit, init
clr rxshift ;clear input buffer
add #(BAUD/2), &CCR1 ;startbit + 1.5 bits -> first bit
mov #CCIE|CCIS_0|SCS, &CCTL1;set compare mode, sample bits
jmp .Lrxex ;set state,...
.Lrxdatabit: ;save databit
bit #SCCI, &CCTL1 ;measure databit
xor #BIT0, r2 ; XXX inverted input
rrc.b rxshift ;rotate in databit
.Lrxex: add #BAUD, &CCR1 ;one bit delay
incd rxbit ;setup next state
reti
; void serPutc(char)
;use an other Capture/Compare than for receiving (full duplex).
;this one is without interrupts and OUTMOD, because only
;this way P1.1 can be used. P1.1 is prefered because the
;BSL is on that pin too.
.global putchar
.type putchar, @function
putchar: ;send a byte
mov #0, &CCTL2 ;select compare mode
and #0xff, r15 ;make sure its a byte
mov #10, r13 ;ten bits: Start, 8 Data, Stop
rla r15 ;shift in start bit (0)
bis #0x0200, r15 ;set tenth bit (1), thats the
stop bit
mov &TAR, &CCR2 ;set up start time
.Lt1lp: add #BAUD, &CCR2 ;set up for one bit
rrc r15 ;shift data trough carry
jc .Lt1 ;test carry bit
//~ .Lt0: bic.b #TX, &P1OUT ;generate pulse
.Lt0: bis.b #TX, &P1OUT ;generate pulse
jmp .Ltc ;
//~ .Lt1: bis.b #TX, &P1OUT ;generate pause
.Lt1: bic.b #TX, &P1OUT ;generate pause
jmp .Ltc ;
.Ltc: bit #CCIFG, &CCTL2 ;wait for compare
jz .Ltc ;loop until the bit is set
bic #CCIFG, &CCTL2 ;clear for next loop
dec r13 ;decrement bit counter
jnz .Lt1lp ;loop until all bits are tx'ed
mov #1, r15 ;signal success to the caller
ret