/***********************************************************************************
Filename: UART_CC111x_CC251x_DMA.c
Description: This example sends/receives data on UART0, using DMA method.
Comments: To execute this example, compile one SMARTRF04EB unit as transmitter,
by activating the UART_TST_MODE_TX definition, then compile another
unit as receiver, by activating the UART_TST_MODE_RX definition.
Pressing S1 makes the transmitter send its allocated uartTxBuffer[]
to the receiver. The transferred data will arrive at uartRxBuffer[]
and can be verified using the debugger.
For more detailed info about the UART functionality, please study
the design note DN112_Using_UART_in_CC111xFx_CC243x_and_CC251xFx.
Note:
Once the UART receiver has been enabled (U0CSR.RE = 1) it will
automatically trigger data reception as soon the Start bit is
detected. The transmitter I/O should therefor be configured
before the receiver, such that potential pin toggling (during
I/O configuration of the transmitter) does not trigger data
reception at the receiver side. Also, remember to use common
ground for the TX unit and RX unit!
***********************************************************************************/
/***********************************************************************************
* INCLUDES
*/
#include <hal_types.h>
#include <hal_defs.h>
#include <hal_cc8051.h>
#include <ioCCxx10_bitdef.h>
#include <dma.h>
#if (chip == 2510)
#include <ioCC2510.h>
#endif
#if (chip == 1110)
#include <ioCC1110.h>
#endif
#if (chip == 2511)
#include <ioCC2511.h>
#endif
#if (chip == 1111)
#include <ioCC1111.h>
#endif
/***********************************************************************************
* CONSTANTS
*/
// Size of allocated UART RX/TX buffer (just an example)
#define SIZE_OF_UART_RX_BUFFER 200
#define SIZE_OF_UART_TX_BUFFER SIZE_OF_UART_RX_BUFFER
// UART test characters
#define UART_TST_CHAR_1 0xA5
#define UART_TST_CHAR_2 0xB5
// Test definitions
#define UART_TST_MODE_RX
//#define UART_TST_MODE_TX
// Baudrate = 57.6 kbps (U0BAUD.BAUD_M = 34, U0GCR.BAUD_E = 11)
#define UART_BAUD_M 34
#define UART_BAUD_E 11
/***********************************************************************************
* LOCAL VARIABLES
*/
// Buffer+index for UART RX/TX
static uint8 __xdata uartRxBuffer[SIZE_OF_UART_RX_BUFFER];
static uint8 __xdata uartTxBuffer[SIZE_OF_UART_TX_BUFFER];
static uint16 __xdata uartTxIndex;
static uint16 __xdata uartRxIndex;
// Variable for buffer indexing
static uint16 __xdata i;
// Variable for UART packet monitoring
static uint8 __xdata uartPktReceived = 1;
// DMA descriptor for UART RX/TX
static DMA_DESC __xdata uartDmaRxTxCh[2];
// Prototype for local functions
void uart0StartRxDmaChan( DMA_DESC *uartDmaRxDescr,
uint8 uartDmaRxChan,
uint8* uartRxBuf,
uint16 uartRxBufSize);
void uart0StartTxDmaChan( DMA_DESC *uartDmaTxDescr,
uint8 uartDmaTxChan,
uint8* uartTxBuf,
uint16 uartTxBufSize);
/***********************************************************************************
* @fn main
*
* @brief Send/receive data on UART0, using DMA.
*
* @param void
*
* @return 0
*/
int main (void)
{
/***************************************************************************
* Setup test stuff
*/
// Initialize P0_1 for SRF04EB S1 button
P0SEL &= ~BIT1;
P0DIR &= ~BIT1;
P0INP |= BIT1;
// Initialise the allocated UART buffers:
for (i = 0; i < SIZE_OF_UART_RX_BUFFER; i++)
{
uartTxBuffer[i] = (i%2) ? UART_TST_CHAR_1 : UART_TST_CHAR_2;
uartRxBuffer[i] = 0;
}
/***************************************************************************
* Setup I/O ports
*
* Port and pins used by USART0 operating in UART-mode are
* RX : P0_2
* TX : P0_3
* CT/CTS : P0_4
* RT/RTS : P0_5
*
* These pins can be set to function as peripheral I/O to be be used by UART0.
* The TX pin on the transmitter must be connected to the RX pin on the receiver.
* If enabling hardware flow control (U0UCR.FLOW = 1) the CT/CTS (Clear-To-Send)
* on the transmitter must be connected to the RS/RTS (Ready-To-Send) pin on the
* receiver.
*/
// Configure USART0 for Alternative 1 => Port P0 (PERCFG.U0CFG = 0)
// To avoid potential I/O conflict with USART1:
// configure USART1 for Alternative 2 => Port P1 (PERCFG.U1CFG = 1)
PERCFG = (PERCFG & ~PERCFG_U0CFG) | PERCFG_U1CFG;
// Configure relevant Port P0 pins for peripheral function:
// P0SEL.SELP0_2/3/4/5 = 1 => RX = P0_2, TX = P0_3, CT = P0_4, RT = P0_5
P0SEL |= BIT5 | BIT4 | BIT3 | BIT2;
/***************************************************************************
* Configure UART
*
* The system clock source used is the HS XOSC at 26 MHz speed.
*/
// Set system clock source to 26 Mhz XSOSC to support maximum transfer speed,
// ref. [clk]=>[clk_xosc.c]
SLEEP &= ~SLEEP_OSC_PD;
while( !(SLEEP & SLEEP_XOSC_S) );
CLKCON = (CLKCON & ~(CLKCON_CLKSPD | CLKCON_OSC)) | CLKSPD_DIV_1;
while (CLKCON & CLKCON_OSC);
SLEEP |= SLEEP_OSC_PD;
// Initialise bitrate = 57.6 kbps (U0BAUD.BAUD_M = 34, U0GCR.BAUD_E = 11)
U0BAUD = UART_BAUD_M;
U0GCR = (U0GCR&~U0GCR_BAUD_E) | UART_BAUD_E;
// Initialise UART protocol (start/stop bit, data bits, parity, etc.):
// USART mode = UART (U0CSR.MODE = 1)
U0CSR |= U0CSR_MODE;
// Start bit level = low => Idle level = high (U0UCR.START = 0)
U0UCR &= ~U0UCR_START;
// Stop bit level = high (U0UCR.STOP = 1)
U0UCR |= U0UCR_STOP;
// Number of stop bits = 1 (U0UCR.SPB = 0)
U0UCR &= ~U0UCR_SPB;
// Parity = disabled (U0UCR.PARITY = 0)
U0UCR &= ~U0UCR_PARITY;
// 9-bit data enable = 8 bits transfer (U0UCR.BIT9 = 0)
U0UCR &= ~U0UCR_BIT9;
// Level of bit 9 = 0 (U0UCR.D9 = 0), used when U0UCR.BIT9 = 1
// Level of bit 9 = 1 (U0UCR.D9 = 1), used when U0UCR.BIT9 = 1
// Parity = Even (U0UCR.D9 = 0), used when U0UCR.PARITY = 1
// Parity = Odd (U0UCR.D9 = 1), used when U0UCR.PARITY = 1
U0UCR &= ~U0UCR_D9;
// Flow control = disabled (U0UCR.FLOW = 0)
U0UCR &= ~U0UCR_FLOW;
// Bit order = LSB first (U0GCR.ORDER = 0)
U0GCR &= ~U0GCR_ORDER;
/***************************************************************************
* Transfer UART data
*/
while(1)
{
#ifdef UART_TST_MODE_RX
// Use debugger to check received UART packet
if(uartPktReceived)
{
uartPktReceived = 0;
for (i = 0; i < SIZE_OF_UART_RX_BUFFER; i++)
{
uartRxBuffer[i] = 0;
}
uart0StartRxDmaChan(&uartDmaRxTxCh[0], 0, uartRxBuffer, SIZE_OF_UART_RX_BUFFER);
}
#else
// Start UART TX when S1 pressed
if ( !(P0 & BIT1) )
{
uart0StartTxDmaChan(&uartDmaRxTxCh[1], 1, uartTxBuffer, SIZE_OF_UART_TX_BUFFER);
}
#endif
}
return 0;
}
/***********************************************************************************
* LOCAL FUNCTIONS
*/
/***********************************************************************************
* @fn uart0StartTxDmaChan
*
* @brief Function which sets up a DMA channel for UART0 TX.
*
* @param DMA_DESC *uartDmaTxDescr - pointer to DMA descriptor for UART TX
* uint8 uartDmaTxChan - DMA channel number for UART TX
* uint8* uartTxBuf - pointer to allo
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
cc1110 basic software examples.rar_51 cc1110开发_Examples_cc1110_d (318个子文件)
t3_down_cc2510.cspy.bat 2KB
clk_32xosc_cc2510.cspy.bat 2KB
sleep_int_cc2510.cspy.bat 2KB
clk_lowRC_cc2510.cspy.bat 2KB
clk_xosc_cc2510.cspy.bat 2KB
t3_modulo_cc2510.cspy.bat 2KB
wdt_wd_cc2510.cspy.bat 2KB
clk_hfrc_cc2510.cspy.bat 2KB
dma_prev_trigger_cc2510.cspy.bat 2KB
wdt_timer_cc2510.cspy.bat 2KB
dma_man_trigger_cc2510.cspy.bat 2KB
t4_pwm_cc2510.cspy.bat 2KB
t3_free_cc2510.cspy.bat 2KB
t2tex_cc2510.cspy.bat 2KB
pm3_cc2510.cspy.bat 2KB
pm1_cc2510.cspy.bat 2KB
pm0_cc2510.cspy.bat 2KB
t1updown_cc2510.cspy.bat 2KB
t2int_cc2510.cspy.bat 2KB
t1mod_cc2510.cspy.bat 2KB
t1free_cc2510.cspy.bat 2KB
t1cap_cc2510.cspy.bat 2KB
pm2_cc2510.cspy.bat 2KB
t1dsm_cc2510.cspy.bat 2KB
flash_cpu_cc2510.cspy.bat 2KB
io_multi_in_out_cc2510.cspy.bat 2KB
flash_dma_cc2510.cspy.bat 2KB
spi1_slave_cc2510.cspy.bat 2KB
spi0_master_cc2510.cspy.bat 2KB
io_in_cc2510.cspy.bat 2KB
io_out_cc2510.cspy.bat 2KB
radio_carrier_freq_cc2510.cspy.bat 2KB
spi2_slave_cc2510.cspy.bat 2KB
spi0_slave_cc2510.cspy.bat 2KB
adc_cc2510_adc_cont_dma_seq.cspy.bat 2KB
spi1_master_cc2510.cspy.bat 2KB
adc_cc2510_adc_extra_int_single.cspy.bat 2KB
rnd_adc_cc2510.cspy.bat 2KB
template_cc2510.cspy.bat 2KB
template_cc1110.cspy.bat 2KB
rnd_rssi_cc2510.cspy.bat 2KB
adc_cc2510_adc_cont_int_single.cspy.bat 2KB
adc_cc2510_cpu_poll_single.cspy.bat 2KB
UART_CC111x_CC251x_DMA.cspy.bat 2KB
UART_CC111x_CC251x_Polling.cspy.bat 2KB
UART_CC111x_CC251x_ISR.cspy.bat 2KB
UART_CC111x_CC251x_DMA.c 16KB
UART_CC111x_CC251x_polling.c 11KB
powermode2.c 10KB
adc_cont_dma_seq.c 10KB
t1_mod.c 10KB
UART_CC111x_CC251x_ISR.c 10KB
powermode3.c 10KB
t1_updown.c 10KB
powermode1.c 9KB
flash_dma.c 9KB
flash_cpu.c 9KB
t1_cap.c 9KB
t1_free.c 9KB
dma_prev_trigger.c 9KB
t1_dsm.c 9KB
rnd_rssi.c 8KB
t4_pwm.c 8KB
spi_ex2_slave.c 8KB
sleep_int.c 8KB
powermode0.c 8KB
io_out.c 7KB
spi_ex0_master.c 7KB
io_multi_in_out.c 7KB
spi_ex1_master.c 7KB
spi_ex1_slave.c 7KB
io_in.c 7KB
spi_ex0_slave.c 7KB
dma_man_trigger.c 7KB
wdt_wd.c 7KB
radio_carrier_freq.c 6KB
adc_extra_int_single.c 6KB
clk_hfrc.c 6KB
clk_lowRC.c 6KB
t3_down.c 6KB
t3_modulo.c 6KB
adc_cpu_poll_single.c 6KB
t2_int.c 6KB
rnd_adc.c 6KB
wdt_timer.c 5KB
t3_free.c 5KB
t2_tex.c 5KB
clk_xosc.c 4KB
template.c 4KB
clk_32xosc.c 4KB
adc_cc2510_adc_cont_int_single.dbgdt 6KB
adc_cc2510_cpu_poll_single.dbgdt 6KB
UART_CC111x_CC251x_ISR.dbgdt 5KB
rnd_adc_cc2510.dbgdt 5KB
t3_down_cc2510.dbgdt 5KB
adc_cc2510_adc_extra_int_single.dbgdt 5KB
rnd_rssi_cc2510.dbgdt 5KB
dma_prev_trigger_cc2510.dbgdt 5KB
t4_pwm_cc2510.dbgdt 5KB
UART_CC111x_CC251x_DMA.dbgdt 5KB
共 318 条
- 1
- 2
- 3
- 4
资源评论
寒泊
- 粉丝: 75
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (大赛作品)STM32实现的F072RB NUCLEO智能家居控制.zip
- STM32实现的数字示波器源码+数字信号处理教程、配套实例.zip
- 【cookie续续】【cookie续续】【cookie续续】
- 低功耗STM32实现的F411开发板(原理图+PCB源文件+官方例程+驱动等).zip
- 基于stm32实现的 nucleo-L476的智能灯(操作说明+源码).zip
- 基于STM32实现的 NUCLEO板设计彩色LED照明灯(纯cubeMX开发).zip
- 基于STM32实现的 的联合调试侦听设备解决方案(原理图、PCB源文件、调试工具、视频).zip
- 基于STM32实现的 人群定位、调速智能风扇设计(程序、设计报告、视频演示).zip
- 哔哩下载姬(DownKyi)
- 千纬认字app再次更新,增加部首、笔画动画功能
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功