Other Parts Discussed in Thread: CC3235S
Tool/software: Code Composer Studio
Hi TI,
I am trying to establish connection between my launch pad cc3235s as master and power supply (uses rs232) for that i have usb to ttl converter.
and here i am using both uart port of cc3235s, one for debugger and another for ttl. see following picture to get idea what i am trying to do.
firstly i want to establish connection with single slave once it is done than i will send same data with some modification(as per requirement) to the another slave.
in first step:
i am using uartecho program.
uint8_t getStatusB[] = { 0xFF, 0x08, 0x02, 0x00, 0x01, 0x01, 0x00, 0x0B };
this is the command which i want to sent over uart and in response i should get 28 byte of packet. for i have declared
uint8_t receivedDataPacket[28];
here is my uart initialization part
UART_init(); /* Create a UART with data processing off. */ UART_Params_init(&uartParams); uartParams.writeDataMode = UART_DATA_BINARY; uartParams.readDataMode = UART_DATA_BINARY; uartParams.readReturnMode = UART_RETURN_FULL; uartParams.readCallback=(UART_Callback)readCallback; // uartParams.readEcho = UART_ECHO_OFF; uartParams.dataLength = UART_LEN_8; uartParams.stopBits = UART_STOP_ONE; uartParams.parityType = UART_PAR_NONE; uartParams.baudRate = 9600; uart = UART_open(CONFIG_UART_0, &uartParams); uart2 = UART_open(CONFIG_UART_1, &uartParams); if (uart2 == NULL) { /* UART_open() failed */ while (1) ; } if (uart == NULL) { /* UART_open() failed */ while (1) ; } UART_write(uart, echoPrompt, sizeof(echoPrompt)); UART_write(uart2, echoPrompt2, sizeof(echoPrompt2));
i am using both uarts.
hardware xds110 is connected with uart 0 so debugger is working well. and second uart is connected with my ttl pin p03 and p04 , and my slave is not connected only ttl is connected with controller. i am getting echo character over p03 and p04 (or on serial port).
but when i am connecting slave and sending command data instead of single char, no response is coming back.
please help me out and do let me known where i am making mistake.
here is my complete code.
/* * Copyright (c) 2015-2019, 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> #include <unistd.h> #include <string.h> /* Driver Header files */ #include <ti/drivers/GPIO.h> #include <ti/drivers/UART.h> /* Driver configuration */ #include "ti_drivers_config.h" #include "uart_term.h" typedef enum { INTERNAL_LIBRARY, EXTERNAL_LIBRARY } intEx; intEx interanlLIB_or_externaLIB = INTERNAL_LIBRARY; int i = 0; static void sendData(void); static void setData(void); static void readCallback(UART_Handle handle, void *buffer, size_t size); char input2; uint8_t getStatusB[] = { 0xFF, 0x08, 0x02, 0x00, 0x01, 0x01, 0x00, 0x0B }; uint8_t setToRectBQry[] = { 0xFF, 0x12, 0x02, 0x00, 0x00, 0x01, 0x0C, 0x01, 0xC7, 0x03, 0xE8, 0x02, 0x4E, 0x01, 0x00, 0x00, 0x00, 0x24 }; UART_Handle uart; UART_Handle uart2; uint8_t receivedDataPacket[28]; /* * ======== mainThread ======== */ void* mainThread(void *arg0) { uint8_t input; const char echoPrompt[] = "Echoing characters from uart:\r\n"; const char echoPrompt2[] = "Echoing characters from uart2:\r\n"; UART_Params uartParams; /* Call driver init functions */ GPIO_init(); switch (interanlLIB_or_externaLIB) { case INTERNAL_LIBRARY: UART_init(); /* Create a UART with data processing off. */ UART_Params_init(&uartParams); uartParams.writeDataMode = UART_DATA_BINARY; uartParams.readDataMode = UART_DATA_BINARY; uartParams.readReturnMode = UART_RETURN_FULL; uartParams.readCallback=(UART_Callback)readCallback; // uartParams.readEcho = UART_ECHO_OFF; uartParams.dataLength = UART_LEN_8; uartParams.stopBits = UART_STOP_ONE; uartParams.parityType = UART_PAR_NONE; uartParams.baudRate = 9600; uart = UART_open(CONFIG_UART_0, &uartParams); uart2 = UART_open(CONFIG_UART_1, &uartParams); if (uart2 == NULL) { /* UART_open() failed */ while (1) ; } if (uart == NULL) { /* UART_open() failed */ while (1) ; } UART_write(uart, echoPrompt, sizeof(echoPrompt)); UART_write(uart2, echoPrompt2, sizeof(echoPrompt2)); break; case EXTERNAL_LIBRARY: InitTerm(); UART_PRINT("Echoing characters:---\r\n"); break; }; /* Configure the LED pin */ GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); /* Turn on user LED */ GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON); memset((void*) receivedDataPacket, 0, sizeof(receivedDataPacket)); // sendData(); setData(); // while (1) // { // usleep(20000); // UART_read(uart2, &input, sizeof(input)); // UART_write(uart2, &input, sizeof(input)); // } } static void sendData() { /* Loop forever echoing */ while (i < sizeof(setToRectBQry)) { switch (interanlLIB_or_externaLIB) { case INTERNAL_LIBRARY: // UART_write(uart2, &getStatusB[i], sizeof(getStatusB[i])); UART_writePolling(uart2, &setToRectBQry[i], sizeof(setToRectBQry[i])); i++; break; case EXTERNAL_LIBRARY: Message((char*)getStatusB[i++]); usleep(20000); // UART_writePolling(uart, getStatusB, sizeof(getStatusB)); break; }; // UART_write(uart, sendDataPacket, sizeof(sendDataPacket)); // UART_read(uart, &input, 1); } } static void setData() { i = 0; /* Loop forever echoing */ while (i < sizeof(setToRectBQry)) { switch (interanlLIB_or_externaLIB) { case INTERNAL_LIBRARY: UART_write(uart2, &setToRectBQry[i], sizeof(setToRectBQry[i])); // UART_writePolling(uart2, &setToRectBQry[i],sizeof(setToRectBQry[i])); i++; break; case EXTERNAL_LIBRARY: UART_writePolling(uart, getStatusB, sizeof(getStatusB)); break; }; // UART_write(uart, sendDataPacket, sizeof(sendDataPacket)); // UART_read(uart, &input, 1); } } static void readCallback(UART_Handle handle, void *buffer, size_t size) { if(0xFF==(*(uint8_t*)buffer)) { if(size==28) { // ddress_h = ((uint8_t*)buffer)[1]; // address_l = ((uint8_t*)buffer)[2]; // cmd = ((uint8_t*)buffer)[3]; // data = ((uint8_t*)buffer)[4]; // checksum = ((uint8_t*)buffer)[5]; UART_read(uart2, receivedDataPacket, sizeof(receivedDataPacket)); } else // size will always be 28 so this is unneccessary { UART_readCancel(uart2); } } else { UART_readCancel(uart2); } // i=0; // while(i<sizeof(receivedDataPacket)) // { // UART_write(uart2, &receivedDataPacket[i], sizeof(receivedDataPacket[i])); // i++; // } }
thanks in advance.
Br,
sarju bhatnagar