@@ -32,16 +32,24 @@ Finally it polls the INT line and shows its status on SAID1.RGB0.
3232HARDWARE
3333The demo runs on the OSP32 board. Have a cable from the OUT connector to
3434the IN connector so that both SAIDs are in the chain.
35- The OSP32 board has an I2C device (EEPROM) attached to the first SAID,
36- and it is possible to plug in other (5V) I2C devices (like an EEPROM stick)
37- in the I2C connector of the OSP32 board. OSP32 als has a pushbutton
38- connected to the INT line of the SAID with I2C bridge.
35+ The SAID OUT on the OSP32 board is enabled for I2C. On the OSP32 board an I2C
36+ device (EEPROM) is attached to it. One could attach other I2C devices, like
37+ the supplied EEPROM stick, via the header labeled "I2C".
38+ The first phase of this demo, scans for all connected I2C devices on the bus
39+ (it finds at least the EEPROM). The second phase writes/reads the connected
40+ EEPROM. The OSP32 board has a pushbutton connected to the INT line of the
41+ SAID with I2C bridge. In the third phase, pressing the push button instructs
42+ the firmware to change the color of an LED.
3943In Arduino select board "ESP32S3 Dev Module".
4044
45+ BEHAVIOR
46+ During the I2C scan or the EEPROM test, there is no visible behavior.
47+ During the third phase the first RGB (L1.0) of SAID OUT is green
48+ except while the INT button is depressed, then it is red.
49+
4150OUTPUT
42- (press the INT button in the third demo)
4351Welcome to aoosp_i2c.ino
44- version: result 0.1.7 spi 0.2.4 osp 0.1.16
52+ version: result 0.4.1 spi 0.5.1 osp 0.4.1
4553spi: init
4654osp: init
4755
@@ -58,7 +66,7 @@ Bus scan for SAID 001
586638: 38 39 3a 3b 3c 3d 3e 3f
596740: 40 41 42 43 44 45 46 47
606848: 48 49 4a 4b 4c 4d 4e 4f
61- 50: [50] 51 52 53 54 55 56 57
69+ 50: 50 51 52 53 [54] 55 56 57
627058: 58 59 5a 5b 5c 5d 5e 5f
637160: 60 61 62 63 64 65 66 67
647268: 68 69 6a 6b 6c 6d 6e 6f
@@ -68,21 +76,21 @@ SAID 001 has 1 I2C devices (see square brackets)
6876
6977resetinit last 002 loop
7078
71- Read/write (to EEPROM 50 on SAID 001)
72- eeprom 00 0E 49 0E 92 0E DB 0E
73- eeprom 00 0E BE EF 92 0E DB 0E
74- eeprom 00 0E 49 0E 92 0E DB 0E
79+ Read/write (locations 00..07 of EEPROM 54 on SAID 001)
80+ eeprom FF FF FF FF FF FF FF FF (original)
81+ eeprom FF FF BE EF FF FF FF FF (written)
82+ eeprom FF FF FF FF FF FF FF FF (restored)
7583
7684resetinit last 002 loop
7785
78- Polling INT pin (on SAID 001)
86+ Press INT button and check L1.0
7987*/
8088
8189
8290// OSP node address of the SAID to use for I2C
8391#define ADDR 0x001 // OSP32 has SAID1 with I2C on addr 001
8492// I2C device address
85- #define DADDR 0x50 // OSP32 has EEPROM with this address on SAID1
93+ #define DADDR 0x54 // OSP32 has EEPROM with this address on SAID1
8694
8795
8896// Print a table of all I2C device addresses that acknowledge a read
@@ -111,6 +119,7 @@ void i2c_scan() {
111119 // Scan all devices
112120 Serial.printf (" \n Bus scan for SAID %03X\n " ,ADDR);
113121 int count= 0 ;
122+ int found= 0 ;
114123 for ( uint8_t daddr7=0 ; daddr7<0x80 ; daddr7++ ) {
115124 if ( daddr7 % 8 == 0 ) Serial.printf (" %02x: " ,daddr7);
116125 // Try to read at address 0 of device daddr7
@@ -119,10 +128,12 @@ void i2c_scan() {
119128 int i2cfail= result==aoresult_dev_i2cnack || result==aoresult_dev_i2ctimeout;
120129 if ( result!=aoresult_ok && !i2cfail ) { Serial.printf (" i2cread8 %s\n " , aoresult_to_str (result) ); return ; }
121130 if ( i2cfail ) Serial.printf (" %02x " ,daddr7); else Serial.printf (" [%02x]" ,daddr7); // [] brackets indicate presence
131+ if ( !i2cfail && daddr7==DADDR ) found++;
122132 if ( !i2cfail ) count++;
123133 if ( daddr7 % 8 == 7 ) Serial.printf (" \n " );
124134 }
125135 Serial.printf (" SAID %03X has %d I2C devices (see square brackets)\n " , ADDR, count);
136+ if ( !found ) Serial.printf (" WARNING: expect I2C device with address %02X, but did find any\n " ,DADDR);
126137
127138 Serial.printf (" \n " );
128139}
@@ -150,13 +161,22 @@ void i2c_eeprom() {
150161 result= aoosp_exec_i2cenable_get (ADDR,&enable);
151162 if ( result!=aoresult_ok || !enable ) { Serial.printf (" ERROR: there doesn't seem to be a SAID with I2C enabled at %03X (%s)\n " ,ADDR,aoresult_to_str (result)); return ; }
152163
153- Serial.printf (" \n Read/write (to EEPROM %02X on SAID %03X)\n " ,DADDR,ADDR);
164+ // uint8_t flags, rcur, gcur, bcur;
165+ // result= aoosp_send_readcurchn(ADDR, 2, &flags, &rcur, &gcur, &bcur);
166+ // if( result!=aoresult_ok ) { Serial.printf("readcurchn %s\n", aoresult_to_str(result) ); return; }
167+ // Serial.printf("readcurchn: flags %02X rgb %02X %02X %02X\n", flags, rcur, gcur, bcur);
168+
169+ // Power the I2C bus
170+ result= aoosp_exec_i2cpower (ADDR);
171+ if ( result!=aoresult_ok ) { Serial.printf (" i2cpower %s\n " , aoresult_to_str (result) ); return ; }
172+
173+ Serial.printf (" \n Read/write (locations 00..07 of EEPROM %02X on SAID %03X)\n " ,DADDR,ADDR);
154174 // Dump the first 8 bytes of the I2C EEPROM memory
155175 result= aoosp_exec_i2cread8 (ADDR, DADDR, 0x00 , rbuf1, 8 );
156176 if ( result!=aoresult_ok ) { Serial.printf (" i2cread8 %s\n " , aoresult_to_str (result) ); return ; }
157177 Serial.printf (" eeprom" );
158178 for ( int i=0 ; i<8 ; i++ ) Serial.printf (" %02X" ,rbuf1[i]);
159- Serial.printf (" \n " );
179+ Serial.printf (" (original) \n " );
160180
161181 // Modify bytes 2 and 3 of the I2C EEPROM memory
162182 wbuf[0 ]= 0xBE ; wbuf[1 ]=0xEF ;
@@ -168,7 +188,7 @@ void i2c_eeprom() {
168188 if ( result!=aoresult_ok ) { Serial.printf (" i2cread8 %s\n " , aoresult_to_str (result) ); return ; }
169189 Serial.printf (" eeprom" );
170190 for ( int i=0 ; i<8 ; i++ ) Serial.printf (" %02X" ,rbuf2[i]);
171- Serial.printf (" \n " );
191+ Serial.printf (" (written) \n " );
172192
173193 // Restore bytes 2 and 3 of the I2C EEPROM memory
174194 wbuf[0 ]= rbuf1[2 ]; wbuf[1 ]=rbuf1[3 ];
@@ -180,14 +200,14 @@ void i2c_eeprom() {
180200 if ( result!=aoresult_ok ) { Serial.printf (" i2cread8 %s\n " , aoresult_to_str (result) ); return ; }
181201 Serial.printf (" eeprom" );
182202 for ( int i=0 ; i<8 ; i++ ) Serial.printf (" %02X" ,rbuf2[i]);
183- Serial.printf (" \n " );
203+ Serial.printf (" (restored) \n " );
184204
185205 Serial.printf (" \n " );
186206}
187207
188208
189209// Poll the INT pin
190- #define LEDADDR 0x001
210+ #define ADDR_LED 0x001
191211void i2c_int_setup () {
192212 aoresult_t result;
193213 int enable;
@@ -210,11 +230,14 @@ void i2c_int_setup() {
210230 result= aoosp_exec_i2cpower (ADDR);
211231 if ( result!=aoresult_ok ) { Serial.printf (" i2cpower %s\n " , aoresult_to_str (result) ); return ; }
212232
213- // Prepare SAID at LEDADDR for feedback (clear its errors and go active)
214- result= aoosp_send_clrerror (LEDADDR );
233+ // Prepare SAID at ADDR_LED for feedback (clear its errors and go active)
234+ result= aoosp_send_clrerror (ADDR_LED );
215235 if ( result!=aoresult_ok ) { Serial.printf (" clrerror %s\n " , aoresult_to_str (result) ); return ; }
216- result= aoosp_send_goactive (LEDADDR );
236+ result= aoosp_send_goactive (ADDR_LED );
217237 if ( result!=aoresult_ok ) { Serial.printf (" goactive %s\n " , aoresult_to_str (result) ); return ; }
238+
239+ // Instruct user
240+ Serial.printf (" \n Press INT button and check L1.0\n " );
218241}
219242
220243
@@ -226,12 +249,14 @@ void i2c_int_loop() {
226249 if ( result!=aoresult_ok ) { Serial.printf (" readi2ccfg %s\n " , aoresult_to_str (result) ); return ; }
227250 uint8_t intstate= flags & AOOSP_I2CCFG_FLAGS_INT;
228251 if ( intstate ) {
229- result= aoosp_send_setpwmchn (LEDADDR , 0 /* chn*/ , 0x7FFF /* red*/ , 0x0000 /* green*/ , 0x0000 /* blue*/ );
252+ result= aoosp_send_setpwmchn (ADDR_LED , 0 /* chn*/ , 0x7FFF /* red*/ , 0x0000 /* green*/ , 0x0000 /* blue*/ );
230253 if ( result!=aoresult_ok ) { Serial.printf (" setpwmchn %s\n " , aoresult_to_str (result) ); return ; }
231254 } else {
232- result= aoosp_send_setpwmchn (LEDADDR , 0 /* chn*/ , 0x0000 /* red*/ , 0x7FFF /* green*/ , 0x0000 /* blue*/ );
255+ result= aoosp_send_setpwmchn (ADDR_LED , 0 /* chn*/ , 0x0000 /* red*/ , 0x7FFF /* green*/ , 0x0000 /* blue*/ );
233256 if ( result!=aoresult_ok ) { Serial.printf (" setpwmchn %s\n " , aoresult_to_str (result) ); return ; }
234257 }
258+
259+ delay (1 );
235260}
236261
237262
0 commit comments