Other Parts Discussed in Thread: CC1312R,
Dear,
i am using CC1312R launchpad ,CCS v10 and simplelink_cc13x2_26x2_sdk_4_10_00_78/kernel/tirtos/packages.
I am trying to setup a uart commnad link with my IOT device and print out the debug message to PC.
I am new to the this dev system and have some question to ask about , my works is on some reference from the echo example and some source from this forum .
1) For the UART CALLBACK listed in
typedef void(* UART_Callback) (UART_Handle, void *buf, size_t count), does it mean it will ONLY goto callback when it the UART received COUNT byte ?
2) for the return mode,
UART operation | UART_RETURN_FULL | UART_RETURN_NEWLINE |
---|---|---|
UART_read() | Returns when buffer is full | Returns when buffer is full or newline was read |
so in case i use uart_return_newline , does it mean it will goto callback when buffer is full or newline was read?
3) and so
Receive with Return Partial
This use case will read in UART_MODE_BLOCKING until the wanted amount of bytes is received or until a started reception is inactive for a 32-bit period. This UART_read() call can also be used when unknown amount of bytes shall be read. Note: The partial return is also possible in UART_MODE_CALLBACK mode.
whats the main usage of that ?
I want to use this because my IOT device sometimes return unknown amount of byte, but this question is related to (1) and (2)
4) my code was based on the driver page , and was listed as below
/* * Copyright (c) 2015-2017, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ======== uartecho.c ======== */ #include <stdint.h> #include <stddef.h> /* Driver Header files */ #include <ti/drivers/GPIO.h> #include <ti/drivers/UART.h> /* Driver configuration */ #include "ti_drivers_config.h" /* Example/Board Header files */ //#include "Board.h" UART_Handle uart; UART_Handle uart2; UART_Params uartParams,uartParams1; //Receive Continously in UART_MODE_CALLBACK //This case will configure the UART to receive and transmit continously in UART_MODE_CALLBACK, 16 bytes at the time and transmit them back via UART TX. Note that UART_Params.readTimeout is not in use when using UART_MODE_CALLBACK mode. char input[100]; uint8_t uartLineEndCount = 0; #define MAX_NUM_RX_BYTES 100 // Maximum RX bytes to receive in one go #define MAX_NUM_TX_BYTES 100 // Maximum TX bytes to send in one go uint32_t wantedRxBytes; // Number of bytes received so far uint8_t rxBuf[MAX_NUM_RX_BYTES]; // Receive buffer uint8_t txBuf[MAX_NUM_TX_BYTES]; // Transmit buffer char cmd_string[64]; unsigned char received = 0; unsigned char test_cnt = 0; void bc_28_init(void); void Uart2_ReadCallback(UART_Handle handle, void *rxBuf, size_t size) { // UART_read(uart, &input, 1); // uartLineEndCount++; // UART_write(uart, input, 1); } void Uart_ReadCallback(UART_Handle handle, void *rxBuf, size_t size) { unsigned int i; if (size == wantedRxBytes) { // Copy bytes from RX buffer to TX buffer for(i = 0; i < size; i++) { txBuf[i] = ((uint8_t*)rxBuf)[i]; // test_cnt++; } // Echo the bytes received back to transmitter // UART_write(uart2, rxBuf, 1); // received = 1; UART_read(uart, rxBuf, wantedRxBytes); } //else { // Handle error or call to UART_readCancel() // } } // Write callback function static void writeCallback(UART_Handle handle, void *rxBuf, size_t size) { // Do nothing } /* * ======== mainThread ======== */ void *mainThread(void *arg0) { const char echoPrompt[] = "Echoing characters:\r\n"; /* Call driver init functions */ GPIO_init(); UART_init(); /* Configure the LED pin */ //GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); /* Turn on user LED */ //GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON); //================ //UART0 for BC28 /* Create a UART with data processing off. */ UART_Params_init(&uartParams); uartParams.readMode = UART_MODE_CALLBACK; uartParams.readCallback = Uart_ReadCallback; uartParams.writeDataMode = UART_DATA_TEXT; uartParams.readDataMode = UART_DATA_TEXT; uartParams.readReturnMode = UART_RETURN_NEWLINE;//UART_RETURN_FULL;//UART_RETURN_NEWLINE; uartParams.readEcho = UART_ECHO_OFF; uartParams.baudRate = 9600; //================ uart = UART_open(CONFIG_UART_0, &uartParams); //================ //UART1 for DEBUG UART_Params_init(&uartParams1); uartParams1.readMode = UART_MODE_CALLBACK; uartParams1.readCallback = Uart2_ReadCallback; uartParams1.writeDataMode = UART_DATA_TEXT;// text mode = processed , binrary is unprocess uartParams1.readDataMode = UART_DATA_TEXT; uartParams1.readReturnMode = UART_RETURN_NEWLINE; uartParams1.readEcho = UART_ECHO_OFF; uartParams1.baudRate = 9600; uart2 = UART_open(CONFIG_UART_1, &uartParams1); //================ UART_write(uart, echoPrompt, sizeof(echoPrompt)); UART_write(uart2, echoPrompt, sizeof(echoPrompt)); if (uart == NULL) { /* UART_open() failed */ while (1); } /* Loop forever echoing */ // UART_read(uart, &input, 1); wantedRxBytes = 52; //desire number of byte to get int rxBytes = UART_read(uart, rxBuf, wantedRxBytes); //int rxBytes2 = UART_read(uart2, rxBuf, wantedRxBytes); bc_init(); while (1) { // memset(cmd_string, 0, sizeof(cmd_string))//; // sprintf(cmd_string,"ABC",0); // UART_write(uart2,cmd_string,strlen(cmd_string)); if(received == 1) { UART_write(uart2, txBuf, wantedRxBytes); //sprintf(cmd_string,"ABC",0); //UART_write(uart2,cmd_string,strlen(cmd_string)); received = 0; } } } /* * uart_call_back_2.c * * Created on: May 4, 2020 * Author: Admin */ /* * .c * * Created on: May 5, 2020 * Author: Admin */ /* bc28 work for NBIOT link CC1312R UART UART0 DIO 04 -- TX DIO 05 -- RX UART1 DIO 18 -- TX DIO 19 -- RX */ const char AT[] = "ATI\r\n"; //const char ATI[] = "ATI\r\n"; void bc_init(void) { UART_write(uart, AT, sizeof(AT)); //UART_write(uart, ATI, sizeof(ATI)); } /* * useful ? from ti forum time = Clock_getTicks(); memset(dumbuf,0,sizeof(dumbuf)); sprintf(txBuf,"System time in clk0Fxn = %lu\n\r",time); UART_write(uart,dumbuf,strlen(dumbuf)); //System_printf("System time in clk0Fxn = %lu\n", (ULong)time); */ //useful reference //e2e.ti.com/.../3195567
my question to the above was , in the code i was assumed i know the received byte and it works fine,
but what if i didnt know the number of byte received?
thanks
Jeff