This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

cc1310串口操作中遇见的问题

Other Parts Discussed in Thread: CC1310

串口配置为回调中断接收

串口接收1bit写入到缓存allreadbuf中,然后解析allreadbuf,

这个时候如果有flash写入操作,串口的中断不能使用。请问如何解决,

是关闭串口中断?cc1310的uartparams属性中没有关闭在打开中断。

  • 这个应该是正常的,flash操作是死锁的的。
    你想做什么?
  • flashdemo_v1.0.0.zip串口跟flash写入不应该冲突,两个独立的模块。提供一份flash操作的demo供参考

  • 我sensor/collector基本完善了。但是sensor里面有一些参数需要设置进去。考虑低功耗的原因:
    我就做了一个根据电量来判断,sensor启动的模式:
    有线模式和无线模式

    有线模式是:串口一直发送ADC采样的数据,中间有个小缓存时间来判断是否有数据接收,串口接收到数据之后,改变自定义的flash块的参数。
    我现在是串口接收到了数据,flash写入也正常,串口有返回。第二次发送串口的回调中断无法接收数据,但是串口可以正常发送出来数据。只是回调中断不能接收。
    需要贴代码吗?串口用的回调函数模式
  • “我现在是串口接收到了数据,flash写入也正常”
    如果你写入返回值是Success,不会影响下次的接收,你可以参考上面viki 的code。
  • 我就是按照他的这样方式做的,没有什么区别。
    void updateMemoryInFlash(void* destAddr, void* sourceAddr, uint16_t nBytes)
    {
    /* Calculate the start address of the destination page */
    uint32_t pageStartAddr = (uint32_t) destAddr
    - ((uint32_t) destAddr % FLASH_PAGE_SIZES) ;


    //uint32_t pageOffset = (uint32_t) destAddr - pageStartAddr;
    memcpy(scratchBuffer, sourceAddr, nBytes);

    /* Disable flash cache */
    VIMSModeSet(VIMS_BASE, VIMS_MODE_DISABLED);
    while (VIMSModeGet(VIMS_BASE) != VIMS_MODE_DISABLED)
    ;

    /* Erase the whole page */
    FlashSectorErase((uint32_t) pageStartAddr);

    /* Write back from the scratch buffer */
    FlashProgram(scratchBuffer, pageStartAddr, nBytes);

    /* Re-enable flash cache */
    VIMSModeSet(VIMS_BASE, VIMS_MODE_ENABLED);
    }


    void USE_UART_init()
    {
    UART_Params uartParams;

    UART_init();
    UART_Params_init(&uartParams);

    uartParams.baudRate = 9600;
    //readMode = UART_MODE_BLOCKING;UART_MODE_CALLBACK
    uartParams.readMode = UART_MODE_CALLBACK;
    uartParams.readCallback = uartReadCallback;
    uartParams.stopBits = UART_STOP_ONE;
    uartParams.parityType = UART_PAR_NONE;
    uartParams.dataLength = UART_LEN_8;

    UartPrintf_init(UART_open(Board_UART0, &uartParams));
    UART_read(hUart, UartRxReadByte, 1);
    }

    static void uartReadCallback(UART_Handle handle, void *rxBuf, size_t size)
    {
    unsigned short bufsize = SEND_BUF_MAX_SIZE;
    //int temps[1];
    UART_control(handle, UARTCC26XX_CMD_RETURN_PARTIAL_ENABLE, NULL);
    //temps[0]=a++ buf_write;
    ADC_buf_write((char*) &UartRxReadByte, 1, &uartCMDWrite, &uartCMDRead, uartCMDBuf,bufsize);

    // UART_write(handle, &UartRxReadByte, 1);
    if (UART_ERROR == UART_read(handle, &UartRxReadByte, 1))
    {

    UART_readCancel(handle);
    return;
    }
    }

    这是我串口的处理的地方,把updateMemoryInFlash屏蔽就没有任何问题。单独的写flash也没有问题。
    memcpy((char *)&(configInRam.AdcConfig.Ver), &protocolBody[sizeof(Uart_InfoConfig)], TempInfo.leng);
    updateMemoryInFlash(configInFlash, &configInRam, sizeof(ApplicationConfig));
    memcpy(&tempbuf, &TempInfo, sizeof(Uart_InfoConfig));

    memcpy(&tempbuf[sizeof(Uart_InfoConfig)], (char *)&(configInRam.AdcConfig.Ver), sizeof(int));
    WiredpackageData(2,&tempbuf,sizeof(int)+sizeof(Uart_InfoConfig),UARTOK);
  • 就是这样子处理的flash,我while一直读写flash,都没有问题。
    串口和flash同时操作不会有影响吗?可我去掉flash这块就可以正常操作
  • 你为什么一直在读写flash?
    不应该是有变化才去更新?
    你试试不要一直while,你直接导入viki给你demo
  • 我的意思是测试下flash读写有木有问题,才用while。
    正常代码里面是串口接收到了数据,在去写入flash。写入完成了,串口的uartReadCallback就在也进不去了。
    我使用的就是demo中flash代码放在sensor工程里面运行的,flash操作。