mini board PCU9669 (and PCA9665) sample code

Dependencies:   mbed PCU9669 utility PCA9665 I2C_slaves parallel_bus

Fork of mini_board_PCU9669_old by InetrfaceProducts NXP

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

Committer:
nxp_ip
Date:
Wed Jul 11 11:33:26 2012 +0000
Revision:
15:20ddef6d35a1
Parent:
14:b2e3797242b6
test

Who changed what in which revision?

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