2 years, 8 months ago.

comunicação RS-485 lpc1768 modbus

First name = Leandro santos silva Country = Brazil Electrical Engineering Student

lpc1768 = master, soft-starter slave

Hi everyone, I would like some help from you, and now I'm practicing in the firmware area. I am trying to perform serial communication from LPC1768 to WEG SOFT-STARTER. I am looking for a difficulty to send my command, I am using ModbusTOOLS software (slave) where it simulates receiving a command, when sending my command is not available, let me post my code below, I would like a guidance and example of code (a send function).

  1. include "mbed.h"
  2. include "lpc17xx.h"

Serial modbus(p9, p10);

volatile char modbus_buffer_char; uint8_t modbus_input_buffer[12]; volatile uint8_t modbus_input_buffer_counter = 0; volatile bool modbus_interrupt_complete = false;

uint16_t modbus_crc(uint8_t* buf, int len) { uint16_t crc = 0xFFFF;

for (int pos = 0; pos < len; pos++) { crc ^= (uint16_t)buf[pos]; XOR byte into least sig. byte of crc

for (int i = 8; i != 0; i) { Loop over each bit if ((crc & 0x0001) != 0) { If the LSB is set crc >>= 1; Shift right and XOR 0xA001 crc ^= 0xA001; } else Else LSB is not set crc >>= 1; Just shift right } } Note, this number has low and high bytes swapped, so use it accordingly (or swap bytes) return crc; } void modbus_read_L1V(char slave_address) { wait_ms(4); modbus.putc(slave_address); modbus.putc(0x03); modbus.putc(0x00); modbus.putc(0x06); modbus.putc(0x00); modbus.putc(0x02); modbus.putc(0x00); modbus.putc(0x00); wait_ms(4);

} int main() {

modbus.baud(9600); printf("start\n\r");

while(1) {

modbus_read_L1V(0x01);

} }

Be the first to answer this question.