xiaobailong24,
附上串口程序:
/* Which events to trigger a UART interrupt */
#define CC26XX_UART_RX_INTERRUPT_TRIGGERS (UART_INT_RX | UART_INT_RT)
/* All interrupt masks */
#define CC26XX_UART_INTERRUPT_ALL (UART_INT_OE | UART_INT_BE | UART_INT_PE |
UART_INT_FE | UART_INT_RT | UART_INT_TX |
UART_INT_RX | UART_INT_CTS)
/*---------------------------------------------------------------------------*/
#define cc26xx_uart_isr UART0IntHandler
/*---------------------------------------------------------------------------*/
static int (*input_handler)(unsigned char c);
/*---------------------------------------------------------------------------*/
void InitGpio(void)
[
PRCMPowerDomainOn(PRCM_DOMAIN_PERIPH);
while((PRCMPowerDomainStatus(PRCM_DOMAIN_PERIPH)
!= PRCM_DOMAIN_POWER_ON));
/* Enable GPIO peripheral */
PRCMPeripheralRunEnable(PRCM_PERIPH_GPIO);
PRCMLoadSet();
while(!PRCMLoadGet());
IOCPinTypeGpioOutput(IOID_6);
IOCPinTypeGpioOutput(IOID_7);
IOCPinTypeGpioOutput(IOID_25);
IOCPinTypeGpioOutput(IOID_27);
GPIOPinWrite(GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_25 | GPIO_PIN_27,0);
]
void UartConfig(void)
[
//power_and_clock(void)
/* Power on the SERIAL PD */
PRCMPowerDomainOn(PRCM_DOMAIN_SERIAL);
while(PRCMPowerDomainStatus(PRCM_DOMAIN_SERIAL)
!= PRCM_DOMAIN_POWER_ON);
/* Enable UART clock in active mode */
PRCMPeripheralRunEnable(PRCM_PERIPH_UART0);
PRCMLoadSet();
while(!PRCMLoadGet());
// //accessible(void)
// /* First, check the PD */
// if(PRCMPowerDomainStatus(PRCM_DOMAIN_SERIAL)
// != PRCM_DOMAIN_POWER_ON) [
// return false;
// ]
// /* Then check the 'run mode' clock gate */
// if(!(HWREG(PRCM_BASE + PRCM_O_UARTCLKGR) & PRCM_UARTCLKGR_CLK_EN)) [
// return false;
// ]
// //disable_interrupts(void)
// /* Acknowledge UART interrupts */
// IntDisable(INT_UART0);
// /* Disable all UART module interrupts */
// UARTIntDisable(UART0_BASE, CC26XX_UART_INTERRUPT_ALL);
// /* Clear all UART interrupts */
// UARTIntClear(UART0_BASE, CC26XX_UART_INTERRUPT_ALL);
//
// //enable_interrupts(void)
// /* Clear all UART interrupts */
// UARTIntClear(UART0_BASE, CC26XX_UART_INTERRUPT_ALL);
// /* Enable RX-related interrupts only if we have an input handler */
// if(input_handler) [
// /* Configure which interrupts to generate: FIFO level or after RX timeout */
// UARTIntEnable(UART0_BASE, CC26XX_UART_RX_INTERRUPT_TRIGGERS);
// /* Acknowledge UART interrupts */
// IntEnable(INT_UART0);
// ]
//configure(void)
uint32_t ctl_val = UART_CTL_UARTEN | UART_CTL_TXE;
/*
* Make sure the TX pin is output / high before assigning it to UART control
* to avoid falling edge glitches
*/
IOCPinTypeGpioOutput(IOID_3);
GPIOPinWrite(GPIO_PIN_3, 1);
/*
* Map UART signals to the correct GPIO pins and configure them as
* hardware controlled.
*/
IOCPinTypeUart(UART0_BASE, IOID_2, IOID_3,
IOID_UNUSED, IOID_UNUSED);
/* Configure the UART for 115,200, 8-N-1 operation. */
UARTConfigSetExpClk(UART0_BASE, SysCtrlClockGet(),
115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
/*
* Generate an RX interrupt at FIFO 1/2 full.
* We don't really care about the TX interrupt
*/
UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX7_8, UART_FIFO_RX4_8);
/* Enable FIFOs */
HWREG(UART0_BASE + UART_O_LCRH) |= UART_LCRH_FEN;
// if(input_handler) [
// ctl_val += UART_CTL_RXE;
// ]
ctl_val += UART_CTL_RXE;
/* Enable TX, RX (conditionally), and the UART. */
HWREG(UART0_BASE + UART_O_CTL) = ctl_val;
]
*/
IOCPinTypeGpioOutput(IOID_3);
GPIOPinWrite(GPIO_PIN_3, 1);
/*
* Map UART signals to the correct GPIO pins and configure them as
* hardware controlled.
*/
IOCPinTypeUart(UART0_BASE, IOID_2, IOID_3,
IOID_UNUSED, IOID_UNUSED);
/* Configure the UART for 115,200, 8-N-1 operation. */
UARTConfigSetExpClk(UART0_BASE, SysCtrlClockGet(),
115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX7_8, UART_FIFO_RX4_8);
/* Enable FIFOs */
HWREG(UART0_BASE + UART_O_LCRH) |= UART_LCRH_FEN;
ctl_val += UART_CTL_RXE;
/* Enable TX, RX (conditionally), and the UART. */
HWREG(UART0_BASE + UART_O_CTL) = ctl_val;
]
void main(void)
[
uint8_t Led = 1;
uint8_t TempChar;
uint32_t delay;
uint32_t i;
//外部时钟初始化
oscillators_select_lf_xosc();
//GPIO初始化
InitGpio();
for(delay=0;delay<50000;delay++)
[
for(i=0; i<100; i++);
]
GPIOPinWrite(GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_25 | GPIO_PIN_27,1);
UartConfig();
GPIOPinWrite(GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_25 | GPIO_PIN_27,0);
while(1)
[
UARTCharPut(UART0_BASE, TempChar++);
// for(delay=0;delay<50000;delay++)
// [
// for(i=0; i<100; i++);
// ]
if(Led != 0)
Led = 0;
else
Led = 1;
GPIOPinWrite(GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_25 | GPIO_PIN_27,Led);
TempChar = (uint8_t)UARTCharGet(UART0_BASE);
if(TempChar == '1')
break;
]
]