Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Here is an example code to use the CJMCU-752 SC16IS752 I2C to dual channel UART conversion module with an Arduino using the I2C interface. In this example, we will use the first UART channel to communicate with a serial device.
- First, download and install the SC16IS752 Arduino library from the following GitHub repository: https://github.com/ernestk-git/SC16IS752-Arduino-Library.
- This code creates a simple "echo" between the Serial Monitor and a serial device connected to the first UART channel of the SC16IS752 module. It reads data from the Serial Monitor and sends it to the UART channel, and vice versa.
- Connect the CJMCU-752 SC16IS752 module to the Arduino as follows:
- VCC pin to 5V (or 3.3V, depending on your module's voltage level)
- GND pin to GND
- SDA pin to the SDA pin on your Arduino (A4 on the Uno, Leonardo, or Nano; pin 20 on the Mega)
- SCL pin to the SCL pin on your Arduino (A5 on the Uno, Leonardo, or Nano; pin 21 on the Mega)
- If your SC16IS752 module has a different I2C address, you can change the sc16is752Address constant accordingly.
- Please note that you may need to use pull-up resistors (typically 4.7kΩ) for the SDA and SCL lines. Some SC16IS752 modules might already have pull-up resistors on board; in that case, you don't need to add external ones.
- */
- #include <Arduino.h>
- #include <Wire.h>
- #include <SC16IS752.h>
- const byte sc16is752Address = 0x4D; // I2C address of the SC16IS752 module (depends on A0, A1 pin configuration)
- SC16IS752 sc16is752 = SC16IS752(sc16is752Address, &Wire);
- void setup() {
- Serial.begin(9600);
- Wire.begin();
- sc16is752.begin(SC16IS752_PROTOCOL_I2C);
- // Configure UART channel 1
- sc16is752.beginUART(9600, SC16IS752::CONFIG_8N1, SC16IS752::CHANNEL_1);
- sc16is752.enableFIFO(SC16IS752::CHANNEL_1, true);
- sc16is752.setRxTriggerLevel(SC16IS752::CHANNEL_1, 1);
- Serial.println("CJMCU-752 SC16IS752 I2C Dual Channel UART Module Example");
- }
- void loop() {
- // Read data from Serial Monitor and send it to UART channel 1
- if (Serial.available()) {
- char data = Serial.read();
- sc16is752.write(SC16IS752::CHANNEL_1, data);
- }
- // Read data from UART channel 1 and send it to Serial Monitor
- if (sc16is752.available(SC16IS752::CHANNEL_1)) {
- char data = sc16is752.read(SC16IS752::CHANNEL_1);
- Serial.print(data);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement