zoukankan      html  css  js  c++  java
  • QCC300x UART

    未经本人同意 请务转载 David QQ:435398366

    QCC300X 的PIO[0]和PIO[1]为UART的RX和TX,PIO[8]和PIO[9]为UART的RTS和CTS

    注意 QCC300X 的IO电压是1.8V的,最好不要直接接到3.3V 或 5V ,测试UART的时候用3.3V的MCU 通讯没有问题,量产的时候最好不要这样接

    未命名_meitu_0

    PStool -> UART configuration when under VM control -> 08a0

    clipboard

    PStool -> UART baud rate in bits per second -> 38400

    clipboard

    xIDE -> project -> properties -> transport -> raw

    clipboard

    clipboard

    clipboard

    注意检查一下配置 PIO[0] 和 PIO[1] 是否被其他功能占用(这里浪费了几天时间,程序运行就报错,导致串口功能几天没处理好,DEBUG 调试发现是在电池温度检测函数报错,默认PIO 0 用作电池温度检测,如果电池没有温度传感器可以将温控功能禁用)

    clipboard

    测试代码

    #include "sink_debug.h"
    #include <print.h>
    #include <stream.h>
    #include <sink.h>
    #include <source.h>
    #include <string.h>
    #include <panic.h>
    #include <message.h>
    #include <app/uart/uart_if.h>
    #include <uart.h>
    
    #ifdef DEBUG_UART
    #define UART_DEBUG(x)          DEBUG(x)
    #define UART_DUMP(buf,cnt)     do{uint32 idx=0;for(idx=0;idx<cnt;idx++){DEBUG(("%02X",buf[idx]));}DEBUG(("
    "));}while(0)
    #else
    #define UART_DEBUG(x)
    #define UART_DUMP(buf,cnt)
    #endif
    
    typedef struct{
        TaskData task;
        Sink uart_sink;
        Source uart_source;
    } UARTStreamTaskData;
    
    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);
    
    void uart_data_stream_init(void){
        /* Assign task message handler */
        theUARTStreamTask.task.handler = UARTStreamMessageHandler;
        /* Configure uart settings */
        StreamUartConfigure(VM_UART_RATE_115K2, VM_UART_STOP_ONE, 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);
        /*(void)VmalMessageSinkTask(StreamSinkFromSource(theUARTStreamTask.uart_source),&theUARTStreamTask.task); */
        UART_DEBUG(("uart_data_stream_init"));
    }
    
    void UARTStreamMessageHandler (Task pTask, MessageId pId, Message pMessage){
        UART_DEBUG(("UARTStreamMessageHandler
    "));
        switch (pId){
            case MESSAGE_MORE_DATA:
                uart_data_stream_rx_data(((MessageMoreData *)pMessage)->source);
                break;
            default:
                break;
        }
    }
    
    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);
        UART_DUMP(data,length);
        /* 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_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); 
    
        /*printf("%c", (*(dest+offset)));*/
    
        /* Flush the data out to the uart */ 
        PanicZero(SinkFlush(theUARTStreamTask.uart_sink, length)); 
    } 
    
     
    

      

    未经本人同意 请务转载 David QQ:435398366
  • 相关阅读:
    发布一个扩展Repeater的模板控件,带自动分页功能
    webservice 测试窗体只能用于来自本地计算机的请求
    FCKeditor编辑器中设置默认文本行高和字体大小
    程序员的个人性格
    程序设计模式的有趣解释-追MM
    集锦一
    UML简介(原创)
    一位IT从业人员的心路历程
    一个初级测试工程师的工作总结
    "与熊共舞"(转载)
  • 原文地址:https://www.cnblogs.com/dreamblog/p/9482150.html
Copyright © 2011-2022 走看看