研究一段串口参数设置代码

原创
2014/04/05 00:42
阅读数 694

研究一段USCI发送初始化代码:

static void ULP_sendData(void)
{
    // Configure UART pins
    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P2,
            GPIO_PIN0 | GPIO_PIN1, GPIO_SECONDARY_MODULE_FUNCTION);
    // Configure UART - 9600 baud
    EUSCI_A_UART_initAdvance(__MSP430_BASEADDRESS_EUSCI_A0__,
            EUSCI_A_UART_CLOCKSOURCE_ACLK, 0x03, 0x00, 0x92,
            EUSCI_A_UART_NO_PARITY, EUSCI_A_UART_LSB_FIRST,
            EUSCI_A_UART_ONE_STOP_BIT, EUSCI_A_UART_MODE,
            EUSCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION);
    EUSCI_A_UART_enable(__MSP430_BASEADDRESS_EUSCI_A0__);
    // Trigger DMA transfer by sending intro byte
    while (!(UCA0IFG & UCTXIFG)) {
    }
    // byte has no significance, just used as DMA trigger
    EUSCI_A_UART_transmitData(__MSP430_BASEADDRESS_EUSCI_A0__, 0x44);
    // Set up DMA0, Repeated single transfer, length = index, UART trigger, transmit bytes
    DMA_init(__MSP430_BASEADDRESS_DMAX_3__, DMA_CHANNEL_0, DMA_TRANSFER_REPEATED_SINGLE, *FRAM_write_index,
             DMA_TRIGGERSOURCE_15, DMA_SIZE_SRCBYTE_DSTBYTE, DMA_TRIGGER_RISINGEDGE);
    // Transfer from ADC_results in FRAM, increment
    DMA_setSrcAddress(__MSP430_BASEADDRESS_DMAX_3__, DMA_CHANNEL_0, (unsigned long)FRAM_ADC_RESULTS + 2,
                      DMA_DIRECTION_INCREMENT);
    // Transfer to TX buffer for UART (UCA0), unchanged
    DMA_setDstAddress(__MSP430_BASEADDRESS_DMAX_3__, DMA_CHANNEL_0, (unsigned long)&UCA0TXBUF,
                      DMA_DIRECTION_UNCHANGED);
    DMA_enableTransfers(__MSP430_BASEADDRESS_DMAX_3__, DMA_CHANNEL_0);
    DMA_enableInterrupt(__MSP430_BASEADDRESS_DMAX_3__, DMA_CHANNEL_0);
    // Go to sleep until transfer finishes
    __bis_SR_register(LPM0_bits + GIE);
    __no_operation();
    EUSCI_A_UART_disable(__MSP430_BASEADDRESS_EUSCI_A0__);                      // Stop UART (UCA0)
    DMA_disableTransfers(__MSP430_BASEADDRESS_DMAX_3__, DMA_CHANNEL_0);         // disable DMA
}

函数原型:

bool EUSCI_A_UART_initAdvance( uint32_t baseAddress,
                               uint8_t selectClockSource,
                               uint16_t clockPrescalar,
                               uint8_t firstModReg,
                               uint8_t secondModReg,
                               uint8_t parity,
                               uint16_t msborLsbFirst,
                               uint16_t numberofStopBits,
                               uint16_t uartMode,
                               uint8_t overSampling
                               )
展开阅读全文
打赏
0
5 收藏
分享
加载中
更多评论
打赏
0 评论
5 收藏
0
分享
返回顶部
顶部