mini board PCU9669 (and PCA9665) sample code
Dependencies: mbed PCU9669 utility PCA9665 I2C_slaves parallel_bus
Fork of mini_board_PCU9669_old by
Sample code for PCU9669 (PCU9661, PCA9663, PCA9661 and PCA9665) evaluation board.
PCU9669 evaluation board: Mini board PCU9669
User manual is available -> http://www.nxp.com/documents/user_manual/UM10580.pdf
main_PCA9665.c@4:c50d5596cb47, 2012-03-21 (annotated)
- Committer:
- nxp_ip
- Date:
- Wed Mar 21 05:47:54 2012 +0000
- Revision:
- 4:c50d5596cb47
- Parent:
- 3:42f933bd12b3
- Child:
- 5:57c345099873
release test 0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nxp_ip | 0:de9a15767563 | 1 | /** A sample code for "mini board PCU9669/PCA9665" |
nxp_ip | 0:de9a15767563 | 2 | * |
nxp_ip | 0:de9a15767563 | 3 | * @author Tedd OKANO, NXP Semiconductors |
nxp_ip | 0:de9a15767563 | 4 | * @version 0.9 |
nxp_ip | 0:de9a15767563 | 5 | * @date 14-Feb-2011 |
nxp_ip | 0:de9a15767563 | 6 | * |
nxp_ip | 0:de9a15767563 | 7 | * Released under the MIT License: http://mbed.org/license/mit |
nxp_ip | 0:de9a15767563 | 8 | * |
nxp_ip | 0:de9a15767563 | 9 | * An operation sample of PCU9669/PCA9665 I2C bus controller. |
nxp_ip | 0:de9a15767563 | 10 | * The mbed accesses the bus controller's parallel port (8/2 bit address and 8 bit data) by bit-banging. |
nxp_ip | 0:de9a15767563 | 11 | * The bit-banging is poerformed by PortInOut function of mbed library. |
nxp_ip | 0:de9a15767563 | 12 | * |
nxp_ip | 0:de9a15767563 | 13 | * To make the code porting easier, all codes are partitioned into layers to abstract other parts. |
nxp_ip | 0:de9a15767563 | 14 | * The mbed specific parts are concentrated in lowest layer: "hardware_abs.*". |
nxp_ip | 0:de9a15767563 | 15 | * This module may need to be modified for the porting. |
nxp_ip | 0:de9a15767563 | 16 | * |
nxp_ip | 0:de9a15767563 | 17 | * All other upper layers are writen in standard-C. |
nxp_ip | 0:de9a15767563 | 18 | * |
nxp_ip | 0:de9a15767563 | 19 | * base code is written from 05-Sep-2011 to 09-Sep-2011. |
nxp_ip | 0:de9a15767563 | 20 | * And demo code has been build on 11-Sep-2011. |
nxp_ip | 0:de9a15767563 | 21 | * Debug and code adjustment has been done on 08-Sep-2011. |
nxp_ip | 0:de9a15767563 | 22 | * Small sanitization for main.cpp. All mbed related codes are moved in to "hardware_abs.*". 13-Oct-2011 |
nxp_ip | 0:de9a15767563 | 23 | * hardware_abs are moved into parallel_bus library folder, 3 LED driver operation sample 13-Feb.-2012 |
nxp_ip | 0:de9a15767563 | 24 | * PCU9669 and PCA9665 codes are packed in a project 14-Feb-2012. |
nxp_ip | 0:de9a15767563 | 25 | * |
nxp_ip | 0:de9a15767563 | 26 | * Before builidng the code, please edit the file mini_board_PCU9669/config.h |
nxp_ip | 0:de9a15767563 | 27 | * Uncomment the target name what you want to target. |
nxp_ip | 0:de9a15767563 | 28 | */ |
nxp_ip | 0:de9a15767563 | 29 | |
nxp_ip | 0:de9a15767563 | 30 | |
nxp_ip | 0:de9a15767563 | 31 | #include "config.h" |
nxp_ip | 0:de9a15767563 | 32 | #include "PCA9665_access.h" |
nxp_ip | 0:de9a15767563 | 33 | #include "PCx9955_reg.h" |
nxp_ip | 0:de9a15767563 | 34 | #include "PCA9629_reg.h" |
nxp_ip | 0:de9a15767563 | 35 | #include "hardware_abs.h" // to use install_ISR() and wait_sec() functions |
nxp_ip | 0:de9a15767563 | 36 | #include "utility.h" |
nxp_ip | 0:de9a15767563 | 37 | |
nxp_ip | 0:de9a15767563 | 38 | #include "mbed.h" // this header is required only when printf() is used. |
nxp_ip | 0:de9a15767563 | 39 | |
nxp_ip | 0:de9a15767563 | 40 | #ifdef CODE_FOR_PCA9665 |
nxp_ip | 0:de9a15767563 | 41 | |
nxp_ip | 0:de9a15767563 | 42 | char PCx9955_reg_data[] = { |
nxp_ip | 0:de9a15767563 | 43 | 0x80, // Strat register address with AutoIncrement bit |
nxp_ip | 0:de9a15767563 | 44 | 0x00, 0x05, // MODE1, MODE2 |
nxp_ip | 0:de9a15767563 | 45 | 0xAA, 0xAA, 0xAA, 0xAA, // LEDOUT[3:0] |
nxp_ip | 0:de9a15767563 | 46 | 0x80, 0x00, // GRPPWM, GRPFREQ |
nxp_ip | 0:de9a15767563 | 47 | PWM_INIT, PWM_INIT, PWM_INIT, PWM_INIT, // PWM[3:0] |
nxp_ip | 0:de9a15767563 | 48 | PWM_INIT, PWM_INIT, PWM_INIT, PWM_INIT, // PWM[7:4] |
nxp_ip | 0:de9a15767563 | 49 | PWM_INIT, PWM_INIT, PWM_INIT, PWM_INIT, // PWM[11:8] |
nxp_ip | 0:de9a15767563 | 50 | PWM_INIT, PWM_INIT, PWM_INIT, PWM_INIT, // PWM[15:12] |
nxp_ip | 0:de9a15767563 | 51 | IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, // IREF[3:0] |
nxp_ip | 0:de9a15767563 | 52 | IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, // IREF[7:4] |
nxp_ip | 0:de9a15767563 | 53 | IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, // IREF[11:8] |
nxp_ip | 0:de9a15767563 | 54 | IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, // IREF[15:12] |
nxp_ip | 0:de9a15767563 | 55 | 0x08 // OFFSET: 1uS offsets |
nxp_ip | 0:de9a15767563 | 56 | }; |
nxp_ip | 0:de9a15767563 | 57 | |
nxp_ip | 0:de9a15767563 | 58 | char PCx9955_reg_read_start_address = 0x80; |
nxp_ip | 0:de9a15767563 | 59 | |
nxp_ip | 0:de9a15767563 | 60 | char read_buffer[ 46 ]; |
nxp_ip | 0:de9a15767563 | 61 | |
nxp_ip | 0:de9a15767563 | 62 | |
nxp_ip | 0:de9a15767563 | 63 | int main() { |
nxp_ip | 0:de9a15767563 | 64 | int count = 0; |
nxp_ip | 0:de9a15767563 | 65 | int i; |
nxp_ip | 0:de9a15767563 | 66 | int j; |
nxp_ip | 0:de9a15767563 | 67 | |
nxp_ip | 0:de9a15767563 | 68 | printf( "\r\nPCU9665 simple demo program on mbed\r\n build : %s (UTC), %s \r\n\r\n", __TIME__, __DATE__ ); |
nxp_ip | 0:de9a15767563 | 69 | |
nxp_ip | 0:de9a15767563 | 70 | hardware_initialize(); // initializing bit-banging parallel port |
nxp_ip | 0:de9a15767563 | 71 | PCA9665_init(); |
nxp_ip | 0:de9a15767563 | 72 | |
nxp_ip | 0:de9a15767563 | 73 | // set_speed_mode( SPEED_STD_MODE ); |
nxp_ip | 0:de9a15767563 | 74 | // set_speed_mode( SPEED_FAST_MODE ); |
nxp_ip | 0:de9a15767563 | 75 | set_speed_mode( SPEED_FAST_MODE_PLUS ); |
nxp_ip | 0:de9a15767563 | 76 | |
nxp_ip | 0:de9a15767563 | 77 | // set_buffer_mode( DISABLE ); |
nxp_ip | 0:de9a15767563 | 78 | set_buffer_mode( ENABLE ); |
nxp_ip | 0:de9a15767563 | 79 | |
nxp_ip | 0:de9a15767563 | 80 | while ( 1 ) { |
nxp_ip | 0:de9a15767563 | 81 | for ( i = 0; i < 16; i++ ) { |
nxp_ip | 0:de9a15767563 | 82 | for ( j = 0; j < 256; j += 4 ) { |
nxp_ip | 0:de9a15767563 | 83 | |
nxp_ip | 0:de9a15767563 | 84 | PCx9955_reg_data[ 9 + i ] = j; |
nxp_ip | 0:de9a15767563 | 85 | |
nxp_ip | 0:de9a15767563 | 86 | if ( i & 0x01 ) |
nxp_ip | 0:de9a15767563 | 87 | set_buffer_mode( ENABLE ); |
nxp_ip | 0:de9a15767563 | 88 | else |
nxp_ip | 0:de9a15767563 | 89 | set_buffer_mode( DISABLE ); |
nxp_ip | 0:de9a15767563 | 90 | |
nxp_ip | 0:de9a15767563 | 91 | i2c_write( PCx9955_ADDR0, PCx9955_reg_data, sizeof( PCx9955_reg_data ), NEXT_RESTART ); |
nxp_ip | 0:de9a15767563 | 92 | i2c_write( PCx9955_ADDR0, &PCx9955_reg_read_start_address, sizeof( PCx9955_reg_read_start_address ), NEXT_RESTART ); |
nxp_ip | 0:de9a15767563 | 93 | i2c_read( PCx9955_ADDR0, read_buffer, sizeof( read_buffer ), STOP ); |
nxp_ip | 0:de9a15767563 | 94 | |
nxp_ip | 0:de9a15767563 | 95 | // dump_read_data( read_buffer, sizeof( read_buffer ) ); |
nxp_ip | 0:de9a15767563 | 96 | |
nxp_ip | 0:de9a15767563 | 97 | wait( 0.01 ); |
nxp_ip | 0:de9a15767563 | 98 | count++; |
nxp_ip | 0:de9a15767563 | 99 | } |
nxp_ip | 0:de9a15767563 | 100 | } |
nxp_ip | 0:de9a15767563 | 101 | for ( i = 0; i < 16; i++ ) |
nxp_ip | 0:de9a15767563 | 102 | PCx9955_reg_data[ 9 + i ] = 0; |
nxp_ip | 0:de9a15767563 | 103 | } |
nxp_ip | 0:de9a15767563 | 104 | } |
nxp_ip | 0:de9a15767563 | 105 | |
nxp_ip | 0:de9a15767563 | 106 | #endif // CODE_FOR_PCA9665 |