Most pertinent code is below, but I can also include a link to the github repo. The code and the tx/rx works when using the TTLMax pictured above, it’s just when using my home-built circuit that it fails. I realize also that this circuit is basically just recreating that TTLMax, and that the components alone cost more than the complete board itself, but i’d love to figure it out.
#include "Modbus.h"
//creates modbus object
Modbus::Modbus(){
hasError = false;
failureCount = 0;
}
//takes a reading from the modbus slave
//has three parameters: The modbus slave unit, the address of a register(uint16_t), and the data type of the register (string)
//returns uint16_t value of the result of the read response
//returns NULL if reading modbus slave fails
int Modbus::readRegisters(ModbusMaster slave, uint16_t Register_Address, String Register_Type){
uint8_t result = slave.readHoldingRegisters(Register_Address, 1);
if(result == slave.ku8MBSuccess){
int data = slave.getResponseBuffer(0);
//data manipulation because we can't have nice things
if(data/32768 >= 1){
return (data-65536);
}else{
return data;
}
}
//failure case
hasError = true;
return 0;
}
//adds +1 to the failure counter
void Modbus::addToFailureCount(){
failureCount++;
}