Hi everyone,
I am using the following files to configure uart for laser distance sensor.
I am able to write command to the Laser sensor and also the laser sensor is responding to them( It makes a beep sound when it responds).
I also tested the TX pin of Sensor using Logic Analyzer , And it shows that there is data on the pins.
Here is the code that i have been using.
/** @file laser_interra.c
*
* @brief Turn ON the laser sensor and measures distance.
*
* @par
* NOTICE: Property of in-Terra Limited www.in-terra.ch .
*/
#include "laser_interra.h"
#include "UART.h"
#ifdef LASER_SENSOR
uint8_t laser_mode;
uint8_t trigger_flag;
uint8_t on_flag;
uint8_t measure_flag;
/*!
* @brief Initialize the laser sensor
*
* @param[in] NONE.
*
* @return Error 0
* Success 1
*/
#define OP_QUEUES_SIZE 3
#define APP_TIMER_PRESCALER NRF_SERIAL_APP_TIMER_PRESCALER
static void sleep_handler(void)
{
__WFE();
__SEV();
__WFE();
}
NRF_SERIAL_DRV_UART_CONFIG_DEF(m_uart1_drv_config,
LASER_RX, LASER_TX,
24/*RTS_PIN_NUMBER*/, 25/*CTS_PIN_NUMBER*/,
NRF_UARTE_HWFC_DISABLED, NRF_UARTE_PARITY_EXCLUDED,
NRF_UARTE_BAUDRATE_19200,
UART_DEFAULT_CONFIG_IRQ_PRIORITY);
#define SERIAL_FIFO_TX_SIZE 32
#define SERIAL_FIFO_RX_SIZE 32
NRF_SERIAL_QUEUES_DEF(serial1_queues, SERIAL_FIFO_TX_SIZE, SERIAL_FIFO_RX_SIZE);
#define SERIAL_BUFF_TX_SIZE 8
#define SERIAL_BUFF_RX_SIZE 8
NRF_SERIAL_BUFFERS_DEF(serial1_buffs, SERIAL_BUFF_TX_SIZE, SERIAL_BUFF_RX_SIZE);
NRF_SERIAL_CONFIG_DEF(serial1_config, NRF_SERIAL_MODE_IRQ,
&serial1_queues, &serial1_buffs, NULL, sleep_handler);
NRF_SERIAL_UART_DEF(serial1_uart, 1);
uint8_t
sensor_init(void)
{
laser_mode=AUTO;
//laser_off();
trigger_flag=0;
on_flag=0;
measure_flag=0;
ret_code_t ret;
ret = nrf_drv_clock_init();
APP_ERROR_CHECK(ret);
ret = nrf_drv_power_init(NULL);
APP_ERROR_CHECK(ret);
nrf_drv_clock_lfclk_request(NULL);
ret = app_timer_init();
APP_ERROR_CHECK(ret);
// Initialize LEDs and buttons.
//bsp_board_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS);
ret = nrf_serial_init(&serial1_uart, &m_uart1_drv_config, &serial1_config);
APP_ERROR_CHECK(ret);
SEGGER_RTT_printf(0,"error:%d\r\n",ret);
return SUCCESS;
}
uint8_t
sensor_read(void)
{
char tx_message = 0x44;
char rx_message;
ret_code_t ret;
ret = nrf_serial_write(&serial1_uart,
&tx_message,
1,
NULL,
0/*NRF_SERIAL_MAX_TIMEOUT*/);
ret = nrf_serial_read(&serial1_uart, &rx_message,1, NULL,0);
SEGGER_RTT_printf(0,"error:%d\r\n",ret);
nrf_serial_rx_drain(&serial1_uart);
(void)nrf_serial_flush(&serial1_uart, 0);
}
Also the screenshot of Logic analyzer.
Thanks
Rajat.
Kindly reply asap, Its a bit urgent at the moment.
You have been a lovely community for me so far :D