|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
MSP430F413 Why I am get two START BITS in this TX routine?Can anyone help me out here?
I've included the entire source code. I'm getting two start bits before my data is shifted out LSB first. Thank you for any help! #include "msp430x41x.h" #define TXData R4 #define BitCnt R5 #define COUNTER R6 #define PREAMBLE R7 #define FLAG R8 #define LEDS R9 #define TABLE_ELEMENT R10 #define TIMEOUT2 R11 #define COUNTTX R12 #define CONFIG R14 #define OFFSET R15 TXD EQU 001h ; TXD on P1.0 Bitime_5 EQU 0055 ; ~ 0.5 bit length Bitime EQU 0109 ; Conditions for 9600 Baud SW UART, SMCLK = 1048576 ; ORG 0E000H ; Program Start RESET MOV.W #002FEh,SP ; Define stackpointer CALL #Setup ; Subroutine that initializes registers, interrupts, timers BSL_CODE mov.b #055h,TXData ; Send this byte in inifinite loop -ZZZ INV TXData CALL #TX_Byte_BSL MOV.W #014h,PREAMBLE ; Provides 5 ms Delay MOV.B #1, FLAG call #Delazy jmp RESET Delazy nop TST FLAG JNZ Delazy RET ; ; Basic Timer Interrupt ; BT_ISR DEC.W PREAMBLE ; Counter value used to exact X ms delays TST PREAMBLE JNZ END_ISR DEC.B FLAG MOV.W #019Ah,PREAMBLE ; Provides 100 ms interrupts END_ISR RETI TX_Byte_BSL ;TX_Byten8 BIC.B #BTIE,&IE2 ; Disable Basic Timer interrupt BIS.B #TXD,&P1SEL ; P1.0/1 TA0 for TXD/RXD function MOV.W &TAR,&CCR0 ; Current state of TA counter ADD.W #Bitime,&CCR0 ; Some time till first bit MOV.W #8,BitCnt ; Load Bit counter, STOP,even-PARITY BIT,8data,START MOV.W #OUTMOD0+CCIE,&CCTL0 ; TXD = mark = idle TX_Wait_BSL BIT.W #CCIE,&CCTL0 ; Wait for TX completion JNZ TX_Wait_BSL ; Wait for TX completion BIC.B #TXD,&P1SEL ; TURN OFF P1.0/1 TA0 for TXD/RXD function BIS.B #BTIE,&IE2 ; Enable Basic Timer interrupt RET ; TX Complete TA0_ISR ; RXTXData Buffer holds UART Data ; ADD.W #Bitime,&CCR0 ; Time to next bit UART_TX CMP.W #00h,BitCnt ; JNE TX_Next ; Next bit? BIC.W #CCIE,&CCTL0 ; All Bits TX or RX, Disable Int. RETI ; TX_Next BIC.W #OUTMOD2,&CCTL0 ; TX Mark RRA.W TXData ; LSB is shifted to carry JC TX_Test ; Jump --> bit = 1 TX_Space BIS.W #OUTMOD2,&CCTL0 ; TX Space TX_Test DEC.W BitCnt ; All bits sent (or received)? BIS.B #BTIE,&IE2 ; Enable Basic Timer interrupt RETI ; ; ; Delay Subroutine ; Delay CLR COUNTER Delay1 DEC.W COUNTER JNZ Delay1 RET ; ; Setup Subroutine ; Setup SetupWDT MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop Watchdog Timer SetupFLL BIS.B #XCAP14PF,&FLL_CTL0 ; Configure load caps SetupTA MOV.W #TASSEL1+MC1,&TACTL ; SMCLK, continous mode SetupBT MOV.B #BTSSEL+BTIP2+BTIP1+BTIP0,&BTCTL ; ~244us Int. BIS.B #TXD,&P1DIR ; TXD output on P1 MOV.W #035h,LEDS ; Load "CU" to display on LEDS BIS.B #001h,&P1DIR ; Setup Port 1.0 as an output. IR LED BIS.B #004h,&P1DIR ; Setup Port 1.2 as an output. Charge Pump BIS.B #010h,&P2DIR ; Setup Port 2.4 as an output. Status LED BIS.B #0FFh,&P3DIR ; Setup Port 3 as an output. LEDS BIS.B #0FFh,&P6DIR ; Setup Port 6 as an output. LEDS BIC.B #BIT7,&P1DIR ; Setup Port 1.7 as an input. Test Mode Switch. BIC.B #00Fh,&P2DIR ; Setup Ports 2.0-3 as an inputs. 2.0 - Program 2.1 - Channel BIC.B #BIT4,&P2OUT ; Pull P2.4 Low to turn off the LED. BIS.B #BIT2,&P1OUT ; Turn on Charge Pump for IR LED BIS.B #BTIE,&IE2 ; Enable Basic Timer interrupt MOV.W #OUT,&CCTL0 ; TXD Idle as Mark ; BIS.B #TXD,&P1SEL ; P1.0/1 TA0 for TXD/RXD function CLR CONFIG clr R15 CLR TABLE_ELEMENT EINT RET ; RSEG INTVEC ; MSP430x41x Interrupt vectors ; ORG RESET_VECTOR RESET_VEC DW RESET ; POR, ext. Reset, Watchdog ORG TIMERA0_VECTOR ; Timer_A0 Vector DW TA0_ISR ; Timer_A0 Vector ORG BASICTIMER_VECTOR ; Basic Timer Vector DW BT_ISR ; Basic Timer Vector END ; |
|
|
Re: MSP430F413 Why I am get two START BITS in this TX routine?Your code may have more problems than two start bits. I think you do
not understand how P1.0 behaves. Your initialization code sets BIT0 of P1DIR to 1 and that bit remains 1 unchanged. (Your code actually set it twice. This is not necessary, but does not hurt.) This means P1.0 always acts as an output pin and that is fine. Whether P1.0 is high or low is now controlled by either BIT0 of P1OUT or the OUT bit of TACCTL0 depending on the state of BIT0 of P1SEL. When BIT0 of P1SEL is 0, BIT0 of P1OUT controls the output at P1.0. Your code never sets or clears P1OUT (and POR/PUC does not set or clear it either.) Thus when your code clears BIT0 of P1SEL, you do not know whether P1.0 is a mark or a space. This is not cool. When BIT0 of P1SEL is 1, OUT bit of TACCTL0 controls the output at P1.0. You can use the CPU to change this bit directly. But, in addition, the CPU can set up the TA module to change this bit automatically and precisely at a specific TAR count. If the OUTMODx bits of TACCRL0 are 001, OUT bit (and consequently P1.0) will be Set. If the OUTMODx bits of TACCRL0 are 101, OUT bit (and consequently P1.0) will be Reset. The actual Set/Reset action takes place when TAR counts (up or down) and matches TACCR0. When done correctly, this feature of the TA module gives more precise timing of the output waveform as compared with doing it directly with the CPU to change BIT0 of P1OUT or OUT bit of TACCRL0. See, for example, the code sample "fet410_ta_uart9600.s43" in TI SLAC016F.ZIP Another potential problem is the crystal oscillator startup and FLL+ lock time. I think within the first second or so after power up or reset, you are not going to get 9600 b/s. --- In msp430@..., "neptunetg" <stealsecond@...> wrote: > > Can anyone help me out here? > > I've included the entire source code. I'm getting two start bits > before my data is shifted out LSB first. > > Thank you for any help! > > > #include "msp430x41x.h" > > #define TXData R4 > #define BitCnt R5 > #define COUNTER R6 > #define PREAMBLE R7 > #define FLAG R8 > #define LEDS R9 > #define TABLE_ELEMENT R10 > #define TIMEOUT2 R11 > #define COUNTTX R12 > #define CONFIG R14 > #define OFFSET R15 > TXD EQU 001h ; TXD on P1.0 > Bitime_5 EQU 0055 ; ~ 0.5 bit length > Bitime EQU 0109 ; Conditions for 9600 > Baud SW UART, SMCLK = 1048576 > ; > > ORG 0E000H ; Program Start > RESET > MOV.W #002FEh,SP ; Define stackpointer > CALL #Setup ; Subroutine that > initializes registers, interrupts, timers > BSL_CODE > > mov.b #055h,TXData ; Send this byte in > inifinite loop -ZZZ > INV TXData > CALL #TX_Byte_BSL > MOV.W #014h,PREAMBLE ; Provides 5 ms Delay > MOV.B #1, FLAG > call #Delazy > jmp RESET > > Delazy > nop > TST FLAG > JNZ Delazy > RET > ; > > ; Basic Timer Interrupt > ; > > > BT_ISR > DEC.W PREAMBLE ; Counter value used to > exact X ms delays > TST PREAMBLE > JNZ END_ISR > DEC.B FLAG > MOV.W #019Ah,PREAMBLE ; Provides 100 ms > interrupts > END_ISR > RETI > > TX_Byte_BSL ;TX_Byten8 > BIC.B #BTIE,&IE2 ; Disable Basic Timer > interrupt > BIS.B #TXD,&P1SEL ; P1.0/1 TA0 for TXD/RXD > function > MOV.W &TAR,&CCR0 ; Current state of TA > counter > ADD.W #Bitime,&CCR0 ; Some time till first > bit > MOV.W #8,BitCnt ; Load Bit counter, > STOP,even-PARITY BIT,8data,START > MOV.W #OUTMOD0+CCIE,&CCTL0 ; TXD = mark = idle > TX_Wait_BSL > BIT.W #CCIE,&CCTL0 ; Wait for TX completion > JNZ TX_Wait_BSL ; Wait for TX > completion > BIC.B #TXD,&P1SEL ; TURN OFF P1.0/1 TA0 > for TXD/RXD function > BIS.B #BTIE,&IE2 ; Enable Basic Timer > interrupt > RET ; TX Complete > > TA0_ISR ; RXTXData Buffer holds UART Data > ; > > > ADD.W #Bitime,&CCR0 ; Time to next bit > UART_TX > CMP.W #00h,BitCnt ; > JNE TX_Next ; Next bit? > BIC.W #CCIE,&CCTL0 ; All Bits TX or RX, > Disable Int. > RETI ; > TX_Next > BIC.W #OUTMOD2,&CCTL0 ; TX Mark > RRA.W TXData ; LSB is shifted to carry > JC TX_Test ; Jump --> bit = 1 > TX_Space > BIS.W #OUTMOD2,&CCTL0 ; TX Space > TX_Test > DEC.W BitCnt ; All bits sent (or > received)? > BIS.B #BTIE,&IE2 ; Enable Basic Timer > interrupt > RETI ; > > ; > > ; Delay Subroutine > ; > > > Delay > CLR COUNTER > Delay1 > DEC.W COUNTER > JNZ Delay1 > RET > > ; > > ; Setup Subroutine > ; > > > Setup > SetupWDT MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop Watchdog Timer > SetupFLL BIS.B #XCAP14PF,&FLL_CTL0 ; Configure load caps > SetupTA MOV.W #TASSEL1+MC1,&TACTL ; SMCLK, continous mode > SetupBT MOV.B #BTSSEL+BTIP2+BTIP1+BTIP0,&BTCTL ; ~244us Int. > BIS.B #TXD,&P1DIR ; TXD output on P1 > MOV.W #035h,LEDS ; Load "CU" to display > on LEDS > BIS.B #001h,&P1DIR ; Setup Port 1.0 as an > output. IR LED > BIS.B #004h,&P1DIR ; Setup Port 1.2 as an > output. Charge Pump > BIS.B #010h,&P2DIR ; Setup Port 2.4 as an > output. Status LED > BIS.B #0FFh,&P3DIR ; Setup Port 3 as an > output. LEDS > BIS.B #0FFh,&P6DIR ; Setup Port 6 as an > output. LEDS > BIC.B #BIT7,&P1DIR ; Setup Port 1.7 as > an input. Test Mode Switch. > BIC.B #00Fh,&P2DIR ; Setup Ports 2.0-3 as > an inputs. 2.0 - Program 2.1 - Channel > BIC.B #BIT4,&P2OUT ; Pull P2.4 Low to turn > off the LED. > BIS.B #BIT2,&P1OUT ; Turn on Charge Pump > for IR LED > BIS.B #BTIE,&IE2 ; Enable Basic Timer > interrupt > MOV.W #OUT,&CCTL0 ; TXD Idle as Mark > ; BIS.B #TXD,&P1SEL ; P1.0/1 TA0 for > TXD/RXD function > CLR CONFIG > clr R15 > CLR TABLE_ELEMENT > EINT > RET > > > ; > > RSEG INTVEC ; MSP430x41x Interrupt > vectors > ; > > ORG RESET_VECTOR > RESET_VEC DW RESET ; POR, ext. Reset, > Watchdog > ORG TIMERA0_VECTOR ; Timer_A0 Vector > DW TA0_ISR ; Timer_A0 Vector > ORG BASICTIMER_VECTOR ; Basic Timer Vector > DW BT_ISR ; Basic Timer Vector > END > > ; > > |
| Free Forum Powered by Nabble | Forum Help |