Year End 2024 Sale
Skip to main content

One Wire Serial

NOTE

OneWireSerial API calls are only available on the RAK4630 and RAk3172 WisDuo modules.

RAK_ONEWIRE_SERIAL_RECEIVE_T

Structure with the received data

typedef struct
{
uint8_t* Buffer; ///< Pointer to the buffer
uint8_t Buffersize; ///< Size of the buffer
};

rak_onewire_serial_recv_cb

This callback receives data from the OneWire interface.

 void(* rak_onewire_serial_recv_cb) (SERIAL_PORT port, RAK_ONEWIRE_SERIAL_RECEIVE_T *data)
Functionvoid rak_onewire_serial_recv_cb callback(SERIAL_PORT port, RAK_ONEWIRE_SERIAL_RECEIVE_T *data)
Parametersport - the serial port used
*data - pointer to the received data structure
Returnsvoid

RAKOneWireSerial Class

This API chooses the pin number for one wire serial and prepare the callback function for receiving data.

OneWireSerial(pin, callback)
FunctionRAKOneWireSerial(uint32_t pin, rak_onewire_serial_recv_cb callback)
Parameterspin - the pin number
ONLY UART1_RXD_PIN and UART1_TXD_PIN are supported
callback - the callback for receiving data
not functional in RUI3 V4.1.0
Returnsvoid
warning

The callback function is not functional in RUI3 V4.1.0. Use NULL while declaring the instance!

warning

Available pins for OneWire are only UART1_RXD_PIN and UART1_TXD_PIN!

Click to view the code
       RAKOneWireSerial onewire(UART1_RXD_PIN,NULL);

void setup()
{
Serial.begin(115200);
onewire.begin(115200, RAK_CUSTOM_MODE);
}

void loop()
{
onewire.write("data\r\n");
while(onewire.available())
{
char a = onewire.read();
Serial.printf("%c",a);
}
}

begin

This API sets the speed (baud rate) for the serial communication.

begin(baud, mode)
Functionvoid begin(uint32_t baud, RAK_SERIAL_MODE mode = RAK_DEFAULT_MODE)
Parametersbaud - the baud rate
mode - option, should be RAK_DEFAULT_MODE
Returnsvoid
Click to view the code
       RAKOneWireSerial onewire(UART1_RXD_PIN,NULL);
void setup()
{
Serial.begin(115200);
onewire.begin(115200, RAK_CUSTOM_MODE);
}

void loop()
{
onewire.write("data\r\n");
while(onewire.available())
{
char a = onewire.read();
Serial.printf("%c",a);
}
}

write

This API writes a byte sequence to a specified one wire serial port.

write(buf, size)
Functionsize_t write(const uint8_t *buf, size_t size)
Parametersbuf - pointer to data buffer
size - number of bytes to send
Returnssize_t - the number of bytes sent successfully
Click to view the code
       RAKOneWireSerial onewire(UART1_RXD_PIN,NULL);
void setup()
{
Serial.begin(115200);
onewire.begin(115200, RAK_CUSTOM_MODE);
}

void loop()
{
onewire.write("data\r\n");
while(onewire.available())
{
char a = onewire.read();
Serial.printf("%c",a);
}
}

available

This API gets the number of bytes available for reading from the specified one wire serial port.

available()
Functionint available(void)
Returnsint - the number of bytes available for reading
Click to view the code
       RAKOneWireSerial onewire(UART1_RXD_PIN,NULL);
void setup()
{
Serial.begin(115200);
onewire.begin(115200, RAK_CUSTOM_MODE);
}

void loop()
{
onewire.write("data\r\n");
while(onewire.available())
{
char a = onewire.read();
Serial.printf("%c",a);
}
}

read

This API gets the number of bytes available for reading from the specified one wire serial port.

read()
Functionint read(void)
Returnsint - the byte read or -1 on read fail
Click to view the code
       RAKOneWireSerial onewire(UART1_RXD_PIN,NULL);
void setup()
{
Serial.begin(115200);
onewire.begin(115200, RAK_CUSTOM_MODE);
}

void loop()
{
onewire.write("data\r\n");
while(onewire.available())
{
char a = onewire.read();
Serial.printf("%c",a);
}
}

end

This API closes the one wire serial port.

end()
Functionvoid end(void)
Returnsvoid