@@ -19,7 +19,7 @@ void init_string(char* buffer, int len){
1919 buffer[x] = ' A' + (rand () % 26 );
2020 }
2121 buffer[len-1 ] = 0 ; // add \0 to end of string
22- printf (" \r\n ****\r\n Buffer Len = `%d`, String = `%s`\r\n ****\r\n " ,len,buffer);
22+ // printf("\r\n****\r\nBuffer Len = `%d`, String = `%s`\r\n****\r\n",len,buffer);
2323}
2424
2525// a test to see if the temperature can be read. A I2C failure returns a 0
@@ -41,19 +41,23 @@ void flash_WR(){
4141 I2CEeprom memory (sda,scl,MBED_CONF_APP_I2C_EEPROM_ADDR,32 ,0 );
4242 int num_read = 0 ;
4343 int num_written = 0 ;
44- char test_string[size_of_data] = {0 };
45- char read_string[size_of_data] = {0 };
46- init_string (test_string,size_of_data); // populate test_string with random characters
44+ volatile char test_string[size_of_data] = {0 };
45+ volatile char read_string[size_of_data] = {0 };
46+ init_string ((char *)test_string,size_of_data); // populate test_string with random characters
47+ for (int x = 0 ; x< size_of_data;x++){
48+ read_string[x] = 0 ;
49+ }
4750 // printf("\r\n****\r\n Test String = `%s` \r\n****\r\n",test_string);
4851
49- num_written = memory.write (address,test_string,size_of_data);
50- num_read = memory.read (address,read_string,size_of_data);
51-
52- printf (" \r\n ****\r\n Address = `%d`\r\n Len = `%d`\r\n Num Bytes Written = `%d` \r\n Num Bytes Read = `%d` \r\n Written String = `%s` \r\n Read String = `%s` \r\n ****\r\n " ,address,size_of_data,num_written,num_read,test_string,read_string);
52+ num_written = memory.write (address,(char *)test_string,size_of_data);
53+ num_read = memory.read (address,(char *)read_string,size_of_data);
5354
54- TEST_ASSERT_MESSAGE (strcmp (test_string,read_string) == 0 ," String Written != String Read" );
55- TEST_ASSERT_EQUAL_STRING_MESSAGE (test_string,read_string," String read does not match the string written" );
55+ TEST_ASSERT_MESSAGE (strcmp ((char *)test_string,(char *)read_string) == 0 ," String Written != String Read" );
56+ TEST_ASSERT_MESSAGE (strcmp ((char *)read_string,(char *)test_string) == 0 ," String Written != String Read" );
57+ TEST_ASSERT_EQUAL_STRING_MESSAGE ((char *)test_string,(char *)read_string," String read does not match the string written" );
58+ TEST_ASSERT_EQUAL_STRING_MESSAGE ((char *)read_string,(char *)test_string," String read does not match the string written" );
5659 TEST_ASSERT_EQUAL_MESSAGE (num_written,num_read," Number of bytes written does not match the number of bytes read" );
60+ printf (" \r\n ****\r\n Address = `%d`\r\n Len = `%d`\r\n Num Bytes Written = `%d` \r\n Num Bytes Read = `%d` \r\n Written String = `%s` \r\n Read String = `%s` \r\n ****\r\n " ,address,size_of_data,num_written,num_read,test_string,read_string);
5761
5862}
5963
@@ -67,16 +71,22 @@ void single_byte_WR(){
6771 int w = 0 ;
6872 w = memory.write (address,test);
6973 r = memory.read (address,read);
70- printf (" \r\n ****\r\n Num Bytes Read = %d \r\n Num Bytes Written = %d \r\n Read byte = %d \r\n Written Byte = %d \r\n ****\r\n " ,r,w,read,test);
74+ printf (" \r\n ****\r\n Num Bytes Read = %d \r\n Num Bytes Written = %d \r\n Read byte = `%c` \r\n Written Byte = `%c` \r\n ****\r\n " ,r,w,read,test);
7175
7276 TEST_ASSERT_EQUAL_MESSAGE (test,read," Character Read does not equal character written!" );
7377 TEST_ASSERT_MESSAGE (test == read, " character written does not match character read" )
78+ }
7479
80+ // Test initializing an I2C Object
81+ template <PinName sda, PinName scl>
82+ void test_object (){
83+ I2C i2c (sda,scl);
84+ TEST_ASSERT_MESSAGE (true ," If you hang here your I2C Object has problems" );
7585}
7686
7787utest::v1::status_t test_setup (const size_t number_of_cases) {
7888 // Setup Greentea using a reasonable timeout in seconds
79- GREENTEA_SETUP (40 , " default_auto" );
89+ GREENTEA_SETUP (20 , " default_auto" );
8090 return verbose_test_setup_handler (number_of_cases);
8191}
8292
@@ -88,11 +98,12 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai
8898
8999// Test cases
90100Case cases[] = {
101+ Case (" I2C - Instantiation of I2C Object" ,test_object<MBED_CONF_APP_I2C_SDA,MBED_CONF_APP_I2C_SCL>,greentea_failure_handler),
91102 Case (" I2C - LM75B Temperature Read" ,test_lm75b<MBED_CONF_APP_I2C_SDA,MBED_CONF_APP_I2C_SCL,25 ,20 >,greentea_failure_handler),
92- // Case("I2C - EEProm WR 2Bytes",flash_WR<MBED_CONF_APP_I2C_SDA,MBED_CONF_APP_I2C_SCL,2,1>,greentea_failure_handler),
93- Case (" I2C - EEProm WR 10Bytes" ,flash_WR<MBED_CONF_APP_I2C_SDA,MBED_CONF_APP_I2C_SCL,10 ,1 >,greentea_failure_handler),
94- Case (" I2C - EEProm WR 100 Bytes" ,flash_WR<MBED_CONF_APP_I2C_SDA,MBED_CONF_APP_I2C_SCL,100 ,1 >,greentea_failure_handler),
95103 Case (" I2C - EEProm WR Single Byte" ,single_byte_WR<MBED_CONF_APP_I2C_SDA,MBED_CONF_APP_I2C_SCL,1 >,greentea_failure_handler),
104+ Case (" I2C - EEProm WR 2 Bytes" ,flash_WR<MBED_CONF_APP_I2C_SDA,MBED_CONF_APP_I2C_SCL,2 ,5 >,greentea_failure_handler),
105+ Case (" I2C - EEProm WR 10 Bytes" ,flash_WR<MBED_CONF_APP_I2C_SDA,MBED_CONF_APP_I2C_SCL,10 ,100 >,greentea_failure_handler),
106+ Case (" I2C - EEProm WR 100 Bytes" ,flash_WR<MBED_CONF_APP_I2C_SDA,MBED_CONF_APP_I2C_SCL,100 ,1000 >,greentea_failure_handler),
96107};
97108
98109Specification specification (test_setup, cases);
0 commit comments