logo资料库

CSR8675 QCC300X 开启串口通信UART教程.pdf

第1页 / 共5页
第2页 / 共5页
第3页 / 共5页
第4页 / 共5页
第5页 / 共5页
资料共5页,全文预览结束
开启CSR8675 UART 本节主要做的是一个电脑使用串口工具,向CSR8675发送数据,然后CSR8675发送回来,串 口助手回显的一个功能 1、首先,可以参阅官方关于配置串口的文档,和一些技术博客 I2C and UART Serial Interface Code Examples, CS-327754-AN-1 2、首先打开工程,然后将Project Properties 的 Transport 修改成 Raw。 3、然后打开 Pstool,搜索 Uart,设置波特率为38400,并关闭硬件流控 第 1 页
4、之后回到xIDE,添加两个文件 sink_uart.c ,sink_uart.h 5、sink_uart.h代码如下 #ifndef _SINK_UART_H_ #define _SINK_UART_H_ #include #include #include #include #include #include #include typedef struct { TaskData task; Sink uart_sink; Source uart_source; } UARTStreamTaskData; extern UARTStreamTaskData theUARTStreamTask; extern void uart_data_stream_init(void); #endif 6、sink_uart.c代码如下 #include #include #include 第 2 页
#include #include #include #include #include #include UARTStreamTaskData theUARTStreamTask; static void UARTStreamMessageHandler (Task pTask, MessageId pId, Message pMessage); static void uart_data_stream_rx_data(Source src); static void uart_data_stream_tx_data(const uint8 *data, uint16 length); static void UARTStreamMessageHandler (Task pTask, MessageId pId, Message pMessage) { switch (pId) { case MESSAGE_MORE_DATA: uart_data_stream_rx_data(((MessageMoreData *)pMessage)->source); break; default: break; } } static void uart_data_stream_tx_data(const uint8 *data, uint16 length) { uint16 offset = 0; uint8 *dest = NULL; /* Claim space in the sink, getting the offset to it */ offset = SinkClaim(theUARTStreamTask.uart_sink, length); if(offset == 0xFFFF) Panic(); /* Map the sink into memory space */ dest = SinkMap(theUARTStreamTask.uart_sink); PanicNull(dest); /* Copy data into the claimed space */ memcpy(dest+offset, data, length); /* Flush the data out to the uart */ PanicZero(SinkFlush(theUARTStreamTask.uart_sink, length)); } static void uart_data_stream_rx_data(Source src) { uint16 length = 0; const uint8 *data = NULL; /* Get the number of bytes in the specified source before the next packet boundary */ if(!(length = SourceBoundary(src))) return; /* Maps the specified source into the address map */ data = SourceMap(src); PanicNull((void*)data); /* Transmit the received data */ uart_data_stream_tx_data(data, length); /* Discards the specified amount of bytes from the front of the specified source */ SourceDrop(src, length); } void uart_data_stream_init(void) { /* Assign task message handler */ theUARTStreamTask.task.handler = UARTStreamMessageHandler; /* Configure uart settings */ StreamUartConfigure(VM_UART_RATE_38K4, VM_UART_STOP_ONE, VM_UART_PARITY_NONE); 第 3 页
VM_UART_PARITY_NONE); /* Get the sink for the uart */ theUARTStreamTask.uart_sink = StreamUartSink(); PanicNull(theUARTStreamTask.uart_sink); /* Get the source for the uart */ theUARTStreamTask.uart_source = StreamUartSource(); PanicNull(theUARTStreamTask.uart_source); /* Register uart source with task */ MessageSinkTask(StreamSinkFromSource(theUARTStreamTask.uart_source), &theUARTStreamTask.task); } 7、最后在main.c ,添加 sink_uart.h 头文件 然后在main函数内,添加void uart_data_stream_init()即可 8、关于开发板的接线 第 4 页
9、最后在电脑打开串口助手,选择38400波特率,无奇偶校验,1位停止位,8位数据位 然后发送任意数据,就会收到我们发出去的数据 第 5 页
分享到:
收藏