|
用风火轮当中的串口进行发数据,用示波器看了一下波形,在0-127段波形不正常,在128-255段波形正常。但是串口调试工具都可以正常收到数据。
0-127段图形
![](http://cache.amobbs.com/bbs_upload782111/files_51/ourdev_716565C0JS02.png)
(原文件名:搜狗截图_2012-02-07_15-34-36.png)
128-255段图形,这里用stm32的一个数据图片代替,数据不在这个区间,26。
![](http://cache.amobbs.com/bbs_upload782111/files_51/ourdev_716566MK5535.png)
(原文件名:搜狗截图_2012-02-07_15-34-51.png)
以上难道是发送格式出现问题吗?
//代码
unsigned char timerA_UART_mode = 0;
unsigned int txData;
//------------------------------------------------------------------------------
// Function configures Timer_A for full-duplex UART operation
//------------------------------------------------------------------------------
void TimerA_UART_init(void)
{
DCOCTL = 0x00; // Set DCOCLK to 1MHz
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
BCSCTL2 &= ~DIVS_3; // SMCLK = 1MHz
//P1SEL |= UART_TXD + UART_RXD; // Timer function for TXD/RXD pins
P1SEL |= UART_TXD ;
P1DIR |= UART_TXD; // TXD
//P1DIR &= ~UART_RXD;
TACCTL0 = OUT; // Set TXD Idle as Mark = '1'
// TACCTL1 = SCS + CM1 + CAP + CCIE; // Sync, Neg Edge, Capture, Int
TACTL |= TACLR; // SMCLK, start in continuous mode
TACTL = TASSEL_2 + MC_2; // SMCLK, start in continuous mode
timerA_UART_mode = 1;
}
//------------------------------------------------------------------------------
// Function unconfigures Timer_A for full-duplex UART operation
//------------------------------------------------------------------------------
void TimerA_UART_shutdown(void)
{
timerA_UART_mode = 0;
// P1SEL &= ~(UART_TXD + UART_RXD); // Timer function for TXD/RXD pins
P1SEL &= ~(UART_TXD ); // Timer function for TXD/RXD pins
TACCTL1 &= ~CCIE; // Sync, Neg Edge, Capture, Int
TACTL &= ~MC_3; // Clear TA modes --> Stop Timer Module
P1OUT &= ~UART_TXD;
}
//------------------------------------------------------------------------------
// Outputs one byte using the Timer_A UART
//------------------------------------------------------------------------------
void TimerA_UART_tx(unsigned char byte)
{
while (TACCTL0 & CCIE); // Ensure last char got TX'd
TACCR0 = TAR; // Current state of TA counter
TACCR0 += UART_TBIT; // One bit time till first bit
txData = byte; // Load global variable
txData |= 0x100; // Add mark stop bit to TXData
txData <<= 1; // Add space start bit
TACCTL0 = OUTMOD0 + CCIE; // Set TXD on EQU2 (idle), Int
__bis_SR_register( LPM0_bits + GIE);
}
//------------------------------------------------------------------------------
// Prints a string over using the Timer_A UART
//------------------------------------------------------------------------------
void TimerA_UART_print(char *string)
{
while (*string) {
TimerA_UART_tx(*string++);
}
}
//------------------------------------------------------------------------------
// Timer_A UART - Transmit Interrupt Handler
//------------------------------------------------------------------------------
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A0_ISR(void)
{
static unsigned char txBitCnt = 10;
if (!timerA_UART_mode)
__bic_SR_register_on_exit(LPM3_bits+GIE)
;
else
{
TACCR0 += UART_TBIT; // Add Offset to CCRx
if (--txBitCnt == 0) // All bits TXed?
{
TACCTL0 &= ~CCIE; // All bits TXed, disable interrupt
txBitCnt = 10;
__bic_SR_register_on_exit(LPM0_bits+GIE)
;
}
else {
if (txData & 0x01) {
TACCTL0 &= ~OUTMOD2; // TX Mark '1'
}
else {
TACCTL0 |= OUTMOD2; // TX Space'0'
}
txData >>= 1;
}
}
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|