This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

UART on GPIO PIN

Hello,

I am using nRF52832. My GPS is connected to GPIO pin (15, RX) and (16, TX) of nRF52832. My TCA9535 is connected to GPIO pin (8, SDA) and (7, SCL) of nRF52832. TCA9535 is providing power (3.7 V) to GPS to turn it ON and its working fine (TESTED). I am trying to print data on UART using Terminal COM PORT but unable to print GPS DATA on TERMINAL.

Main.c

#include <Wire.h>
#include <nrf_delay.h>
#include <TCA9535.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "app_uart.h"
#include "app_error.h"
#include "nrf_delay.h"
#include "nrf.h"
#include "bsp.h"
#if defined (UART_PRESENT)
#include "nrf_uart.h"
#endif
#if defined (UARTE_PRESENT)
#include "nrf_uarte.h"
#endif

TCA9535 TCA9535Sensor = TCA9535();

#define MAX_TEST_DATA_BYTES (15U) /**< max number of test bytes to be used for tx and rx. */
#define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */
#define UART_RX_BUF_SIZE 256 /**< UART RX buffer size. */

void tca_init()
{

TCA9535Sensor.begin();
printf("Init complete!\n");

TCA9535Sensor.setPin(12, TCA9535Sensor.OUTPUTa);
printf("TCA9535 is ON!\n");

TCA9535Sensor.writePin(12,TCA9535Sensor.OFF);
printf("OFF!\n");

nrf_delay_ms(1000);

TCA9535Sensor.writePin(12,TCA9535Sensor.ON);
printf("ON!\n");
}

void uart_error_handle(app_uart_evt_t * p_event)
{
uint32_t err_code;
uint8_t byte;

switch (p_event->evt_type)
{
case APP_UART_DATA_READY:
err_code = app_uart_get(&byte);
APP_ERROR_CHECK(err_code);
printf("APP_UART_DATA_READY");
break;

case APP_UART_COMMUNICATION_ERROR:
APP_ERROR_HANDLER(p_event->data.error_communication);
printf("APP_UART_COMMUNICATION_ERROR");
break;

case APP_UART_FIFO_ERROR:
APP_ERROR_HANDLER(p_event->data.error_code);
printf("APP_UART_FIFO_ERROR");
break;

default:
break;
}
}

#ifdef ENABLE_LOOPBACK_TEST
/* Use flow control in loopback test. */
#define UART_HWFC APP_UART_FLOW_CONTROL_ENABLED

/** @brief Function for setting the @ref ERROR_PIN high, and then enter an infinite loop.
*/
static void show_error(void)
{

bsp_board_leds_on();
while (true)
{
// Do nothing.
}
}


/** @brief Function for testing UART loop back.
* @details Transmitts one character at a time to check if the data received from the loopback is same as the transmitted data.
* @note @ref TX_PIN_NUMBER must be connected to @ref RX_PIN_NUMBER)
*/
static void uart_loopback_test()
{
uint8_t * tx_data = (uint8_t *)("\r\nLOOPBACK_TEST\r\n");
uint8_t rx_data;

// Start sending one byte and see if you get the same
for (uint32_t i = 0; i < MAX_TEST_DATA_BYTES; i++)
{
uint32_t err_code;
while (app_uart_put(tx_data[i]) != NRF_SUCCESS);

nrf_delay_ms(10);
err_code = app_uart_get(&rx_data);

if ((rx_data != tx_data[i]) || (err_code != NRF_SUCCESS))
{
show_error();
}
}
return;
}
#else
/* When UART is used for communication with the host do not use flow control.*/
#define UART_HWFC APP_UART_FLOW_CONTROL_DISABLED
#endif

void uart_init()
{
uint32_t err_code;

const app_uart_comm_params_t comm_params =
{
//RX_PIN_NUMBER,
15,
//TX_PIN_NUMBER,
16,
false,
false,
UART_HWFC,
false,
UART_BAUDRATE_BAUDRATE_Baud9600
//#if defined (UART_PRESENT)
//NRF_UART_BAUDRATE_115200
// NRF_UART_BAUDRATE_9600
//#else
// NRF_UARTE_BAUDRATE_115200
//#endif
};


APP_UART_FIFO_INIT(&comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
uart_error_handle,
APP_IRQ_PRIORITY_LOWEST,
err_code);

APP_ERROR_CHECK(err_code);

#ifndef ENABLE_LOOPBACK_TEST
printf("\r\nUART example started.\r\n");
}
/*
void app_uart_put_string(const char* s)
{
uint32_t err_code;
uint8_t len = strlen(s);
for (uint8_t i = 0; i < len; i++)
{
err_code = app_uart_put(s[i]);
APP_ERROR_CHECK(err_code);
}
}
*/

int main() {

tca_init();
uart_init();

while (true)
{
//app_uart_put_string("HELLO");
uint8_t cr;
//app_uart_get(&cr);
while (app_uart_get(&cr) != NRF_SUCCESS);
printf("%c \n",cr);
//app_uart_put(cr);
while (app_uart_put(cr) != NRF_SUCCESS);
printf("%c \n",cr);
}
#else

// This part of the example is just for testing the loopback .
while (true)
{
uart_loopback_test();
}
#endif
}

Related