test code

Dependencies:   mbed SC18IS606

Sample code for SC18IS606 class library

The SC18IS606 : I2C-bus to SPI bridge

Hello program operation sample on Mbed OS6 is available.

Import programSC18IS606_OS6_Hello

operation test on Mbed OS6

This is a "Hello" code for SC18IS606 class library. Showing how to send/receive data to/from SPI bus through this bridge chip. https://os.mbed.com/media/uploads/okano/screenshot_2021-07-14_13.13.55.png

How to wire the SC18IS606 (using evaluation board) https://os.mbed.com/media/uploads/okano/untitled.png

Revision:
4:2759b8e6d5ec
Parent:
2:6d65d24e55ed
Child:
6:741cdb9c5726
--- a/main.cpp	Tue Jul 13 10:48:34 2021 +0000
+++ b/main.cpp	Wed Jul 14 03:00:41 2021 +0000
@@ -16,7 +16,11 @@
 InterruptIn int_line( p21 );
 SC18IS606   bridge( i2c );
 
-#define WAIT_INTERVAL_mS    2
+#define I2C_FREQUENCY       (400 * 1000)    // Hz
+#define SLAVE_SELECT_NUM    0
+#define DATA_LENGTH         256
+
+void    data_check( char *data, int length );
 
 volatile int    int_flag    = false;
 
@@ -28,26 +32,39 @@
 int main()
 {
     printf( "SC18IS606 Hello\r\n" );
-    
+
     int_line.mode( PullUp );
     int_line.fall( &int_handler );
-    i2c.frequency( 400 * 1000 );
+    i2c.frequency( I2C_FREQUENCY );
 
-    char    s[ 256 ];
+    char    snd_data[ DATA_LENGTH ];
+    char    rcv_data[ DATA_LENGTH ];
 
-    for ( int i = 0; i < 256; i++ ) {
-        s[ i ]  = i;
+    for ( int i = 0; i < DATA_LENGTH; i++ ) {
+        snd_data[ i ]  = i;
     }
 
     while(1) {
-        bridge.transfer( s, NULL, sizeof( s ) );
+        bridge.transfer( SLAVE_SELECT_NUM, snd_data, sizeof( snd_data ) );
 
         while ( !int_flag )
             ;
-            
+
         bridge.clear_interrupt();
         int_flag    = false;
 
-        wait_ms( WAIT_INTERVAL_mS );
+        bridge.read_buffer( rcv_data, sizeof( rcv_data ) );
+        //  data_check( rcv_data, DATA_LENGTH );
     }
 }
+
+
+void data_check( char *data, int length )
+{
+    for ( int i = 0; i < length; i++ ) {
+        if ( !(i % 16) )
+            printf( "\r\n %02X :", i );
+        printf( " %02X", data[ i ] );
+    }
+
+}