Skip to content

Commit ffedb19

Browse files
committed
Content update (SPI and I2C sections)
1 parent a879711 commit ffedb19

File tree

4 files changed

+141
-2
lines changed

4 files changed

+141
-2
lines changed

content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/content.md

Lines changed: 141 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ The Nano R4 board uses the following pins for SPI communication:
14121412

14131413
You can communicate via SPI using the dedicated `SPI.h` library, which is included in the Arduino UNO R4 Boards core. The library provides simple functions to initialize the bus, send and receive data and manage multiple devices.
14141414

1415-
The following example demonstrates how to use SPI communication to control an external device:
1415+
The following example demonstrates how to use SPI communication to send and receive data:
14161416

14171417
```arduino
14181418
/**
@@ -1515,7 +1515,13 @@ void sendSPIData() {
15151515

15161516
***To test this example, no external SPI device is required. The code will demonstrate SPI communication patterns, though without a connected device, the received data will typically be `0xFF`.***
15171517

1518-
You can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to see the SPI communication in action. The example shows how to properly select devices, send data and handle responses.
1518+
You can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to see the SPI communication in action. The example sketch shows how to properly select devices, send data and handle responses.
1519+
1520+
![Arduino IDE Serial Monitor output for the SPI example sketch](assets/spi-1.png)
1521+
1522+
The image below shows how the SPI communication from our example appears in the Digilent Waveforms logic analyzer software, with the decoded protocol showing the chip select, clock and data signals being transmitted.
1523+
1524+
![Digilent Waveforms logic analyzer output for SPI](assets/spi-2.png)
15191525

15201526
For connecting multiple SPI devices, you can use different digital pins as additional Chip Select (`CS`) lines while sharing the `MOSI`, `MISO` and `SCK` pins:
15211527

@@ -1565,6 +1571,139 @@ The Nano R4's I²C interface offers the following technical specifications:
15651571
| Operating Voltage | +5 VDC | Same as board |
15661572
| Pull-up Resistors | Internal | Built-in weak pull-ups |
15671573

1574+
The Nano R4 uses the following pins for I²C communication:
1575+
1576+
| **Arduino Pin** | **Microcontroller Pin** | **I²C Function** | **Description** |
1577+
|:---------------:|:-----------------------:|:----------------:|:-----------------:|
1578+
| `A4` | `P004` | SDA | Serial Data Line |
1579+
| `A5` | `P010` | SCL | Serial Clock Line |
1580+
1581+
You can communicate via I²C using the dedicated `Wire.h` library, which is included in the Arduino UNO R4 Boards core. The library provides simple functions to initialize the bus, send and receive data, and manage multiple devices.
1582+
1583+
The following example demonstrates basic I²C communication patterns:
1584+
1585+
```arduino
1586+
/**
1587+
I2C Basic Example for the Arduino Nano R4 Board
1588+
Name: nano_r4_i2c_basic.ino
1589+
Purpose: This sketch demonstrates basic I2C communication
1590+
patterns for protocol analysis.
1591+
1592+
@author Arduino Product Experience Team
1593+
@version 1.0 01/06/25
1594+
*/
1595+
1596+
#include <Wire.h>
1597+
1598+
// Example device address
1599+
const int DEVICE_ADDRESS = 0x48;
1600+
1601+
void setup() {
1602+
// Initialize serial communication and wait up to 2.5 seconds for a connection
1603+
Serial.begin(115200);
1604+
for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500));
1605+
1606+
Serial.println("- Arduino Nano R4 - I2C Basic Example started...");
1607+
1608+
// Initialize I2C communication as master
1609+
Wire.begin();
1610+
1611+
Serial.println("- I2C initialized successfully");
1612+
Serial.println("- Connect protocol analyzer to A4 (SDA) and A5 (SCL)");
1613+
Serial.println("- Starting I2C communication patterns...");
1614+
1615+
delay(2000);
1616+
}
1617+
1618+
void loop() {
1619+
// Write a single byte
1620+
Serial.println("- Writing single byte (0xAA) to device 0x48...");
1621+
Wire.beginTransmission(DEVICE_ADDRESS);
1622+
Wire.write(0xAA);
1623+
Wire.endTransmission();
1624+
1625+
delay(1000);
1626+
1627+
// Write multiple bytes
1628+
Serial.println("- Writing multiple bytes (0x10, 0x20, 0x30) to device 0x48...");
1629+
Wire.beginTransmission(DEVICE_ADDRESS);
1630+
Wire.write(0x10);
1631+
Wire.write(0x20);
1632+
Wire.write(0x30);
1633+
Wire.endTransmission();
1634+
1635+
delay(1000);
1636+
1637+
// Request data from device
1638+
Serial.println("- Requesting 2 bytes from device 0x48...");
1639+
Wire.requestFrom(DEVICE_ADDRESS, 2);
1640+
1641+
// Read any available data
1642+
while (Wire.available()) {
1643+
int data = Wire.read();
1644+
Serial.print("Received: 0x");
1645+
if (data < 16) Serial.print("0");
1646+
Serial.println(data, HEX);
1647+
}
1648+
1649+
delay(2000);
1650+
Serial.println("---");
1651+
}
1652+
```
1653+
***To test this example, no external I²C devices are required. The code will generate I²C communication patterns that can be analized with a protocol analyzer. Without devices connected, read operations will typically return `0xFF`.***
1654+
1655+
You can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to see the I²C operations being performed. Connect a protocol analyzer to pins `A4` (SDA) and `A5` (SCL) to observe the actual I²C protocol signals.
1656+
1657+
![Arduino IDE Serial Monitor output for the I²C example sketch](assets/i2c-1.png)
1658+
1659+
The image below shows how the I²C communication from our example appears in the Digilent Waveforms logic analyzer software, with the decoded protocol showing the device address and data bytes being transmitted.
1660+
1661+
***The I²C protocol requires pull-up resistors on both SDA and SCL lines. __The Nano R4 board does not have internal pull-ups on A4 and A5 to avoid interference with their analog input functionality, so external 4.7kΩ pull-up resistors to +5 VDC are required for proper I²C operation__.***
1662+
1663+
One of the main advantages of I²C is the ability to connect multiple devices to the same bus. Here's how to connect multiple I²C devices:
1664+
1665+
```arduino
1666+
// Example: Communicating with multiple I2C devices
1667+
void communicateWithMultipleDevices() {
1668+
// Device addresses (examples)
1669+
const int SENSOR_ADDRESS = 0x48; // Temperature sensor
1670+
const int DISPLAY_ADDRESS = 0x3C; // OLED display
1671+
const int EEPROM_ADDRESS = 0x50; // External EEPROM
1672+
1673+
// Read from temperature sensor
1674+
Wire.beginTransmission(SENSOR_ADDRESS);
1675+
Wire.write(0x00); // Register to read
1676+
Wire.endTransmission();
1677+
1678+
Wire.requestFrom(SENSOR_ADDRESS, 2);
1679+
if (Wire.available() >= 2) {
1680+
int tempHigh = Wire.read();
1681+
int tempLow = Wire.read();
1682+
Serial.print("Temperature: ");
1683+
Serial.println((tempHigh << 8) | tempLow);
1684+
}
1685+
1686+
// Send data to display
1687+
Wire.beginTransmission(DISPLAY_ADDRESS);
1688+
Wire.write(0x40); // Data mode
1689+
Wire.write(0xFF); // Sample data
1690+
Wire.endTransmission();
1691+
1692+
// Write to EEPROM
1693+
Wire.beginTransmission(EEPROM_ADDRESS);
1694+
Wire.write(0x00); // Memory address
1695+
Wire.write(0x55); // Data to write
1696+
Wire.endTransmission();
1697+
}
1698+
```
1699+
1700+
When working with I²C on the Nano R4 board, there are several key points to keep in mind for successful implementation:
1701+
1702+
- Each I²C device must have a unique address on the bus, so check device datasheets to avoid address conflicts.
1703+
- Keep in mind that I²C is a half-duplex protocol, meaning data flows in only one direction at a time. The master device (your Nano R4 board) controls the clock line and initiates all communication.
1704+
- When connecting multiple devices, simply connect all SDA pins together and all SCL pins together, along with power and ground connections.
1705+
- The Nano R4 board can communicate with up to 127 different I²C devices on the same bus, making it perfect for complex sensor networks and expandable systems.
1706+
15681707
## Support
15691708

15701709
If you encounter any issues or have questions while working with your Nano R4 board, we provide various support resources to help you find answers and solutions.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy