Мокрый пятый щелчокC++

Программы на C++. Форум разработчиков
Anonymous
 Мокрый пятый щелчок

Сообщение Anonymous »

Я пытаюсь просто записывать и читать байты/биты из следующего модуля с помощью Arduino:
https://download.mikroe.com/documents/d ... /47L16.pdf
https://www.mikroe.com/eeram-5v-click
Я пытаюсь записать 01010101, но получаю 11111111 в качестве вывода для чтения записанные данные.
Я пытаюсь записать 01010101, но получаю 11111111 в качестве вывода для чтения записанных данных.
#include

const uint8_t deviceAddress = 0x50; // Change to your device address
const uint8_t registerAddress = 0x01; // Register address (change if necessary)
const uint8_t dataToWrite = 0b01010101; // Data to write (0xAA)

void setup() {
Serial.begin(9600);
Wire.begin();

// Write data to the device
writeData(registerAddress, dataToWrite);
delay(100); // Short delay before reading
}

void loop() {
// Read the data back from the device
readData(registerAddress);

delay(2000); // Wait for 2 seconds before the next read
}

void writeData(uint8_t registerAddress, uint8_t data) {
Wire.beginTransmission(deviceAddress); // Start communication
Wire.write(registerAddress); // Write register address
Wire.write(data); // Write the data to the register
if (Wire.endTransmission() != 0) {
Serial.println("Error: Write operation failed!");
} else {
Serial.print("Written Data: ");
Serial.println(data, BIN); // Print written data in binary format
}
}

void readData(uint8_t registerAddress) {
Wire.beginTransmission(deviceAddress); // Start communication
Wire.write(registerAddress); // Write the register address to read from
if (Wire.endTransmission() != 0) {
Serial.println("Error: Read address transmission failed!");
return; // Exit if transmission fails
}

Wire.requestFrom(deviceAddress, 1); // Request 1 byte from the device
if (Wire.available()) {
uint8_t receivedByte = Wire.read(); // Read the byte
Serial.print("Received Data: ");
Serial.println(receivedByte, BIN); // Print received byte in binary format
} else {
Serial.println("No data available.");
}
}



Подробнее здесь: https://stackoverflow.com/questions/790 ... 7l16-47c16

Вернуться в «C++»