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.

RN4678 UART Problems need help

Other Parts Discussed in Thread: SYSBIOS

Greetings
I m trying to communicate from my Connected LaunchPad TM4C1294 Tiva C Series Board with RN4678 with UART, but no matter what I do, I dont seem recive anything from the Bluetooth modul.
In the setup I m trying to reset and to toggle the RN4678 to make it UART ready, and I tested with an Oscilator if I do it right, and that should work.
The breaks inbetween are higher than in the documentation because there is just a minimum time which has to be reached before pulling the pins up.
Afterwards I try to get into command mode for the bluetooth modul but the modul which should return CMD to signal that it works doesnt come, my programm gets stuck at UART_read

Here is my code it looks very messy because i was trying everything to get it to work. Does someone of you have any idea what I do wrong? I use 120 MHz SysClock. I dont even know what information I could provide that would be usefull. 


#include <stdbool.h>
#include <inc/hw_memmap.h>

/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/cfg/global.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/Memory.h>

/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>

/* TI-RTOS Header files */
#include <driverlib/sysctl.h>
#include <ti/drivers/UART.h>

/* Driverlib headers */
#include <driverlib/gpio.h>
#include <driverlib/pin_map.h>

/*Board Header files */
#include <Board.h>
#include <EK_TM4C1294XL.h>

/* Application headers */
#include "UART_Task.h"
#include "DebuggingMode.h"

//all commands end with carriage return '\r' '\x0d'
#define ENTER_COMMAND_MODE "$$$\r"
#define EXIT_COMMAND_MODE "---\r"
#define PARING_MODE "SM,6\r" //set remote address field SR
#define DEFAULT_MODE "SM,0\r"
#define SET_BLUETOOTH_MODE "SG,2\r"
#define ENABLE_UART "SH,1\r"

#define TURN_ON_DISCOVERY "W\r"
#define CONNECT_TO_DEVICE "C,0006668CB2A4\r"
#define SET_DEVICE_NAME "SN,SteuerungBoard\r"
#define DISPLAY_SETTING "D\r"
#define SET_BAUDRATE_19200 "SU,07\r"

/*
* ======== UART ========
* Echo Characters recieved and show reception on Port N Led 0
*/
void UARTFxn(UArg arg0, UArg arg1)
{
UART_Handle uart;
UART_Params uartParams;

/* 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_NEWLINE;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.baudRate = 115200;
uartParams.dataLength = UART_LEN_8;
uart = UART_open(Board_UART2, &uartParams);

if (uart == NULL) {
System_abort("Error opening the UART");
}

uint32_t wait_ticks = (uint32_t) arg0;

// System_printf("CTS: %d", GPIOPinRead(GPIO_PORTP_BASE, GPIO_PIN_5));
// System_flush();
// while(GPIOPinRead(GPIO_PORTP_BASE, GPIO_PIN_5) != 0) {}

UART_write(uart, ENTER_COMMAND_MODE, sizeof(ENTER_COMMAND_MODE));
//UART_write(uart, DISPLAY_SETTING, sizeof(DISPLAY_SETTING));
memset(input, ' ', sizeof(input));
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_4, 0);
UART_read(uart, &input, MAXLEN);
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_4, 1);
// UART_readPolling(uart, &input, MAXLEN);
System_printf("UART: %s \n", input);
System_flush();


/* Loop forever echoing */
bool needNew = true;
while (1) {
if(needNew) {
//UART_write(uart, '', sizeof(2));
UART_write(uart, ENABLE_UART, sizeof(ENABLE_UART));
needNew = false;
}

memset(input, ' ', sizeof(input));
UART_read(uart, &input, MAXLEN);
inputReady = true;
if(DEBUG){
System_printf("UART: %s \n", input);
System_flush();
}


UART_write(uart, DISPLAY_SETTING, sizeof(DISPLAY_SETTING));

GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 1); // Remove this line to stop echoing!
Task_sleep(50);
GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0);

//Return:
//$ššbš$GPRMC,193615.000,A,4818.6485,N,01634.1126,E,0.03,25.69,261219,,,D*58
//$GPV$GPRMC,193616.000,A,4818.6485,N,01634.1126,E,0.03,25.69,261219,,,D*5B
needNew = true;
Task_sleep(wait_ticks);
}
//TODO: exit command mode after finished communication
UART_write(uart, EXIT_COMMAND_MODE, sizeof(EXIT_COMMAND_MODE));
}

/*
* Setup task function
*/
// prio isnt used, wait_ticks isnt used, ui32SysClock is 120 000 000 Hz
int setup_UART_Task(int prio, uint32_t wait_ticks, uint32_t ui32SysClock) {
Task_Params taskUARTParams;
Task_Handle taskUART;
Error_Block eb;

//Setup Bluetooth module

//Wakeup PM7
// SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM);
// GPIOPinTypeGPIOOutput(GPIO_PORTM_BASE, GPIO_PIN_7);
// GPIOPinWrite(GPIO_PORTM_BASE, GPIO_PIN_7, GPIO_PIN_7);
//RST PP4
GPIOPinTypeGPIOOutput(GPIO_PORTP_BASE, GPIO_PIN_4);
// GPIOPinWrite(GPIO_PORTP_BASE, GPIO_PIN_4, GPIO_PIN_4);
//SW button low

//AN PD2
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_2);
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2, 0);

System_printf("Pulling RST\n");
System_flush();
//Reset Pin Low
GPIOPinWrite(GPIO_PORTP_BASE, GPIO_PIN_4, 0);
// greater than 63 ns
SysCtlDelay(GPIO_PORTD_BASE*1);
//RST high
GPIOPinWrite(GPIO_PORTP_BASE, GPIO_PIN_4, GPIO_PIN_4);
SysCtlDelay(GPIO_PORTD_BASE*0.5);

System_printf("Setting SW_BTN High\n");
System_flush();
//BTN_SW High
//GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2, 0);
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2, GPIO_PIN_2);
SysCtlDelay(GPIO_PORTD_BASE*2);

//Uart Handshake
//CTS RTS auf microcontroller PD4 auf output auf 0 wenn ich empfangen moechte
// GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_4);
//RTS CTS auf microcontroller PP5 auf input CTS ist auf 0 wenn ich schreiben kann
// GPIOPinTypeGPIOInput(GPIO_PORTP_BASE, GPIO_PIN_5);

/* Setup PortN LED1 activity signaling */
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART6);
GPIOPinConfigure(GPIO_PP0_U6RX);
GPIOPinConfigure(GPIO_PP1_U6TX);
GPIOPinTypeUART(GPIO_PORTP_BASE, GPIO_PIN_0 | GPIO_PIN_1);

UART_init();


Error_init(&eb);
Task_Params_init(&taskUARTParams);
taskUARTParams.stackSize = 1024; /* stack in bytes */
taskUARTParams.arg0 = (UArg)wait_ticks;
taskUARTParams.arg1 = (UArg)"";
inputReady = false;

taskUARTParams.priority = prio; /* 0-15 (15 is highest priority on default -> see RTOS Task configuration) */
taskUART = Task_create((Task_FuncPtr)UARTFxn, &taskUARTParams, &eb);
if (taskUART == NULL) {
System_abort("TaskUART create failed");
}

return (0);
}

  • Hello Balint,

    Balint Taschner said:
    The breaks inbetween are higher than in the documentation because there is just a minimum time which has to be reached before pulling the pins up.

    Can you elaborate on this point more? That seems to be relevant to your issue, but we are TM4C experts and have no knowledge of the RN4678 device you are trying to use here.

    Also have you tried to just send/receive UART data with a PC first to make sure it is configured right?

  • I'm not sure where to post about the RN4678 here is the datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/50002519E.pdf

    There is a Software button and which i pull low until the reset is done, then I do and after the reset i pull it high.

    The datasheet says: "Time duration (475 ms) is for reference purposes only. Use the Status Indication pins to verify the exact time when the host MCU can start sending the commands."

    And someone told me that my sysclock might be the fault here and even if u can't help me with the RN4678. I m not quite sure if the sysclt with 120 MHz can change the communication with UART, because I use 115200 baudrate for the UART but when i accually try to read it with an oscilator then i have to set the read frequency to 1Mhz to see my first message correctly. The first message is "$$$/r". other values on the Oscilator are 100khz, 200khz and 250khz tried those and got wrong values until i set it to 1Mhz. this one is wierd to. 

    Edit: The UART communication worked with a GPS modul and I just changed the click modul to the bluetooth modul, and tripple checked if the pins are right and they are. So the configuration should work

  • Hello Balint,

    Are you setting up your code to monitor the status pins properly?

    I am not really clear on the system clock vs baud rate part in terms of what you feel is the issue, but in general one way to test that would be to use UART0 and connect to the PC to see if you are able to send / receive data properly and then adjust your configuration back to UART6 again. Though it sounds like in general UART works well if you can talk to the module.

    You may need to reach out to Microchip for specifics about how to handle that BT module.