PCA9629 a stepper motor controller class library
Class library for PCA9629.
A sample program available on http://mbed.org/users/nxp_ip/code/PCA9629_Hello/
Diff: PCA9629.cpp
- Revision:
- 2:2d07f1c46eb3
- Parent:
- 0:77dbce152406
--- a/PCA9629.cpp Thu Feb 02 05:23:12 2012 +0000 +++ b/PCA9629.cpp Fri Feb 03 03:44:06 2012 +0000 @@ -36,7 +36,6 @@ } void PCA9629::init_registers( void ) { - int error_code; char init_array[] = { 0x80, // register access start address (0x00) with incremental access flag (MSB) 0x30, 0xE2, 0xE4, 0xE6, 0xE0, 0x02, 0x10, // for registers MODE - WDCNTL (0x00 - 0x06 0x00, 0x00, // for registers IP and INTSTAT (0x07, 0x08) @@ -44,14 +43,20 @@ 0x00, 0x00, 0x30, 0x00, 0x82, 0x66, 0x82, 0x06, // for registers SETMODE - CCWPWH (0x12 - 0x19) 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, // for registers CWSCOUNTL - CCWRCOUNTH (0x1A - 0x21) 0x00, 0x00, // for registers EXTRASTEPS0 and EXTRASTEPS1 (0x22, 0x23) - 0x00, 0x00, 0x94 // for registers RMPCNTL - MCNTL (0x24 - 0x26) + 0x00, 0x00, 0x00 // for registers RMPCNTL - MCNTL (0x24 - 0x26) }; - error_code = i2c.write( i2c_addr, init_array, sizeof( init_array ) ); + set_all_registers( init_array, sizeof( init_array ) ); +} + +void PCA9629::set_all_registers( char *a, char size ) +{ + int error_code; + + error_code = i2c.write( i2c_addr, a, size ); if ( error_code ) error( "error @ initializing PCA9629" ); - } void PCA9629::write( RegisterName register_name, char value ) { @@ -121,6 +126,10 @@ return ( data[ 1 ] << 8 | data[ 0 ] ); } +void PCA9629::start( Direction dir ) { + write( MCNTL, 0xA8 | dir ); +} + void PCA9629::stop( void ) { write( MCNTL, 0x00 ); }