I am trying to send and receive a response from a machine using Modbus (TTL to Rs485) and nrf51822.
Connections: R0 -> RX(P0.11) ,D1->TX(p0.09), RE&DE->P0.19,VCC->5V
Just the same as to connect with Arduino (Have implemented with Arduino mega)
I am using Keil for programming and trying to send and receive in hexadecimal format, but I am not sure if even command is transmitted and obviously I am not getting any response.
I am not sure about connections also. Attaching code.
Please let me know where I am wrong.
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#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"
//#define ENABLE_LOOPBACK_TEST /**< if defined, then this example will be a loopback test, which means that TX should be connected to RX to get data loopback. */
#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 uart_error_handle(app_uart_evt_t * p_event)
{
if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
{
APP_ERROR_HANDLER(p_event->data.error_communication);
}