for SC16IS750 test program. Confirming register access method
Revision 1:d9a4b7a4a159, committed 2012-07-18
- Comitter:
- okano
- Date:
- Wed Jul 18 01:45:38 2012 +0000
- Parent:
- 0:bae17cf3178e
- Commit message:
- register init access method can be switched by REGISTER_INIT_BY_RESTART; false = STOP-START, true = RESTART
Changed in this revision
SC16IS750.cpp | Show annotated file Show diff for this revision Revisions of this file |
SC16IS750.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SC16IS750.cpp Wed Jul 18 01:24:33 2012 +0000 +++ b/SC16IS750.cpp Wed Jul 18 01:45:38 2012 +0000 @@ -1,8 +1,10 @@ #include "mbed.h" #include "SC16IS750.h" -#define XTAL_FREQUENCY 14784000 // Hz -#define REGISTER_ACCESS_SIZE 2 +#define XTAL_FREQUENCY 14784000 // Hz +#define REGISTER_ACCESS_SIZE 2 + +#define REGISTER_INIT_BY_RESTART true char init[][ REGISTER_ACCESS_SIZE ] = { { SC16IS750::LCR, 0x80 }, @@ -27,17 +29,12 @@ i2c.frequency( 400 * 1000 ); - baud_setting = XTAL_FREQUENCY / (baud_rate * 16); + baud_setting = XTAL_FREQUENCY / (baud_rate * 16); init[ 1 ][ 1 ] = (char)baud_setting; init[ 2 ][ 1 ] = (char)(baud_setting >> 8); - + init_registers(); -} - -void SC16IS750::init_registers( void ) { - for ( int i = 0; i < (sizeof( init ) / REGISTER_ACCESS_SIZE); i++ ) - i2c.write( i2c_addr, init[ i ], REGISTER_ACCESS_SIZE ); - + i2c.stop(); } @@ -45,7 +42,7 @@ int baud_setting; baud_rate = baud; - baud_setting = XTAL_FREQUENCY / (baud_rate * 16); + baud_setting = XTAL_FREQUENCY / (baud_rate * 16); register_write( SC16IS750::LCR, 0x80 ); register_write( SC16IS750::DLL, (char)baud_setting ); @@ -53,7 +50,12 @@ register_write( SC16IS750::LCR, 0x03 ); } -void SC16IS750::send_str( char *s ) { +void SC16IS750::init_registers( void ) { + for ( int i = 0; i < (sizeof( init ) / REGISTER_ACCESS_SIZE); i++ ) + i2c.write( i2c_addr, init[ i ], REGISTER_ACCESS_SIZE, REGISTER_INIT_BY_RESTART ); +} + +void SC16IS750::send_str( const char *s ) { char buffer[ 65 ]; int i = 1;
--- a/SC16IS750.h Wed Jul 18 01:24:33 2012 +0000 +++ b/SC16IS750.h Wed Jul 18 01:45:38 2012 +0000 @@ -47,7 +47,7 @@ void init_registers( void ); void set_baud( int ); - void send_str( char *s ); + void send_str( const char *s ); void register_write( char register_address, char data ); char register_read( char register_address );