Thank you so much! I think we have already made some progress. Amna joined the forum and added a line for your code and we tested it.
Code:
#include <Wire.h>
const int deviceAddress = 0x01;
void setup() {
int error, n;
Wire.begin();
Wire.setClock(50000); // 50kHz, half the normal speed
Serial.begin(115200);
Serial.println("Starting");
// ------------------------------------------------
// Write data to a register
// ------------------------------------------------
const byte control_word1[] = {0x02, 0x50, 0x00, 0xA4}; // <--- set the right numbers
const byte data1[] = {0x01, 0x00, 0x00, 0x00}; // <-- set the right numbers
Wire.beginTransmission(deviceAddress);
Wire.write(control_word1, 4);
Wire.write(data1, 4);
error = Wire.endTransmission();
if(error == 0)
{
Serial.println("Data succesfully sent");
}
delay(1); // the chip needs some time ?
// ------------------------------------------------
// Read data from a register
// ------------------------------------------------
const byte control_word2[] = {0x02, 0xD0, 0x00, 0xA4}; // <--- set the right numbers
Wire.beginTransmission(deviceAddress);
Wire.write(control_word2, 4);
error = Wire.endTransmission(false); // 'false' for a repeated start
if(error == 0)
{
Serial.println("Register succesfully selected");
}
delay(1); // the chip needs some time ?
n = Wire.requestFrom(deviceAddress, 4);
Serial.println(n);
if(n == 4)
{
Serial.println("Data received");
for( int i=0; i<4; i++)
{
Serial.print("0x");
Serial.print(Wire.read(), HEX);
Serial.print(", ");
}
Serial.println();
}
delay(1); // the chip needs some time ?
}
void loop() {}
and serial monitor output
ets Jul 29 2019 12:21:46
rst:0xc (SW_CPU_RESE\),boot:03 o 2 bF
ets Jul 29 2019 12:21:46
rst:0x1 (POWERON_RESET),boot:0x3 (DOWNLOAD_BOOT(UART0/UART1/SDIO_REI_REO_V2))
waiting for download
: ets Jul 29 2019 12:21:46
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13964
load:0x40080400,len:3600
entry 0x400805f0
Starting
Data succesfully sent
Register succesfully selected
0
I discussed with Amna, she wanted to know Is there something related to shadow register to read and what is it?
I also asked Amna to comment what the bits are, and she replied:
"Pin Config Register is 0xA4 and it has a default value of 0x00 which means it is programmed to get the analog input for motor Speed. whereas we want to run it in with pwm signal. here you can see in image the complete register bits are shown, secondly while sending data to be written it has to be in Least Significant Byte first"
Thanks Koepel!
