These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Committer:
frank26080115
Date:
Sun Mar 20 05:38:56 2011 +0000
Revision:
0:bf7b9fba3924

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frank26080115 0:bf7b9fba3924 1 /***********************************************************************//**
frank26080115 0:bf7b9fba3924 2 * @file i2c_interrupt_test.c
frank26080115 0:bf7b9fba3924 3 * @purpose An example of I2C using interrupt mode to test the I2C driver.
frank26080115 0:bf7b9fba3924 4 * Using I2C at mode I2C master/8bit on LPC1766 to communicate with
frank26080115 0:bf7b9fba3924 5 * SC16IS750/760 Demo Board
frank26080115 0:bf7b9fba3924 6 * @version 2.0
frank26080115 0:bf7b9fba3924 7 * @date 21. May. 2010
frank26080115 0:bf7b9fba3924 8 * @author NXP MCU SW Application Team
frank26080115 0:bf7b9fba3924 9 *---------------------------------------------------------------------
frank26080115 0:bf7b9fba3924 10 * Software that is described herein is for illustrative purposes only
frank26080115 0:bf7b9fba3924 11 * which provides customers with programming information regarding the
frank26080115 0:bf7b9fba3924 12 * products. This software is supplied "AS IS" without any warranties.
frank26080115 0:bf7b9fba3924 13 * NXP Semiconductors assumes no responsibility or liability for the
frank26080115 0:bf7b9fba3924 14 * use of the software, conveys no license or title under any patent,
frank26080115 0:bf7b9fba3924 15 * copyright, or mask work right to the product. NXP Semiconductors
frank26080115 0:bf7b9fba3924 16 * reserves the right to make changes in the software without
frank26080115 0:bf7b9fba3924 17 * notification. NXP Semiconductors also make no representation or
frank26080115 0:bf7b9fba3924 18 * warranty that such application will be suitable for the specified
frank26080115 0:bf7b9fba3924 19 * use without further testing or modification.
frank26080115 0:bf7b9fba3924 20 **********************************************************************/
frank26080115 0:bf7b9fba3924 21 #include "lpc17xx_i2c.h"
frank26080115 0:bf7b9fba3924 22 #include "lpc17xx_libcfg.h"
frank26080115 0:bf7b9fba3924 23 #include "lpc17xx_pinsel.h"
frank26080115 0:bf7b9fba3924 24 #include "debug_frmwrk.h"
frank26080115 0:bf7b9fba3924 25
frank26080115 0:bf7b9fba3924 26 /* Example group ----------------------------------------------------------- */
frank26080115 0:bf7b9fba3924 27 /** @defgroup I2C_sc16is750_int sc16is750_int
frank26080115 0:bf7b9fba3924 28 * @ingroup I2C_Examples
frank26080115 0:bf7b9fba3924 29 * @{
frank26080115 0:bf7b9fba3924 30 */
frank26080115 0:bf7b9fba3924 31
frank26080115 0:bf7b9fba3924 32 /************************** PRIVATE DEFINITIONS *************************/
frank26080115 0:bf7b9fba3924 33 /** Used I2C device definition, should be 0 or 2 */
frank26080115 0:bf7b9fba3924 34 #define USEDI2CDEV 0
frank26080115 0:bf7b9fba3924 35
frank26080115 0:bf7b9fba3924 36 /* Definition of internal register of SC16IS750/760 */
frank26080115 0:bf7b9fba3924 37 #define IODIR 0x0A
frank26080115 0:bf7b9fba3924 38 #define IOSTATE 0x0B
frank26080115 0:bf7b9fba3924 39 #define IOCON 0x0E
frank26080115 0:bf7b9fba3924 40 #define SLVADDR (0x90>>1)
frank26080115 0:bf7b9fba3924 41 #define REGS_ADDR(n) (n<<3)
frank26080115 0:bf7b9fba3924 42
frank26080115 0:bf7b9fba3924 43
frank26080115 0:bf7b9fba3924 44 #if (USEDI2CDEV == 0)
frank26080115 0:bf7b9fba3924 45 #define I2CDEV LPC_I2C0
frank26080115 0:bf7b9fba3924 46 #elif (USEDI2CDEV == 2)
frank26080115 0:bf7b9fba3924 47 #define I2CDEV LPC_I2C2
frank26080115 0:bf7b9fba3924 48 #else
frank26080115 0:bf7b9fba3924 49 #error "I2C device not defined!"
frank26080115 0:bf7b9fba3924 50 #endif
frank26080115 0:bf7b9fba3924 51
frank26080115 0:bf7b9fba3924 52 /************************** PRIVATE VARIABLES *************************/
frank26080115 0:bf7b9fba3924 53 uint8_t menu1[] =
frank26080115 0:bf7b9fba3924 54 "********************************************************************************\n\r"
frank26080115 0:bf7b9fba3924 55 "Hello NXP Semiconductors \n\r"
frank26080115 0:bf7b9fba3924 56 "I2C demo \n\r"
frank26080115 0:bf7b9fba3924 57 "\t - MCU: LPC17xx \n\r"
frank26080115 0:bf7b9fba3924 58 "\t - Core: ARM Cortex-M3 \n\r"
frank26080115 0:bf7b9fba3924 59 "\t - Communicate via: UART0 - 115.2 kbps \n\r"
frank26080115 0:bf7b9fba3924 60 " Communicate with I2C function on SC16IS750/760 Demo Board\n\r"
frank26080115 0:bf7b9fba3924 61 " Use IO function on SC16IS740/750/760 chip to turn ON/OFF LEDs\n\r"
frank26080115 0:bf7b9fba3924 62 "Press '1' to turn ON LEDs, '2' to turn OFF LEDs \n\r"
frank26080115 0:bf7b9fba3924 63 "********************************************************************************\n\r";
frank26080115 0:bf7b9fba3924 64 uint8_t menu2[] = "Demo terminated! \n\r";
frank26080115 0:bf7b9fba3924 65
frank26080115 0:bf7b9fba3924 66 /* Define array data with match data to set internal register value of SC16IS740/750/760 */
frank26080115 0:bf7b9fba3924 67 uint8_t iocon_cfg[2] = {REGS_ADDR(IOCON), 0x00};
frank26080115 0:bf7b9fba3924 68 uint8_t iodir_cfg[2] = {REGS_ADDR(IODIR), 0xFF};
frank26080115 0:bf7b9fba3924 69 uint8_t iostate_cfg_0[2] = {REGS_ADDR(IOSTATE), 0x00};
frank26080115 0:bf7b9fba3924 70 uint8_t iostate_cfg_1[2] = {REGS_ADDR(IOSTATE), 0xFF};
frank26080115 0:bf7b9fba3924 71
frank26080115 0:bf7b9fba3924 72 __IO FlagStatus complete;
frank26080115 0:bf7b9fba3924 73
frank26080115 0:bf7b9fba3924 74 /************************** PRIVATE FUNCTIONS *************************/
frank26080115 0:bf7b9fba3924 75 #if (USEDI2CDEV == 0)
frank26080115 0:bf7b9fba3924 76 void I2C0_IRQHandler(void);
frank26080115 0:bf7b9fba3924 77 #elif (USEDI2CDEV == 2)
frank26080115 0:bf7b9fba3924 78 void I2C2_IRQHandler(void);
frank26080115 0:bf7b9fba3924 79 #endif
frank26080115 0:bf7b9fba3924 80
frank26080115 0:bf7b9fba3924 81 void print_menu(void);
frank26080115 0:bf7b9fba3924 82 void Error_Loop(uint8_t ErrorCode);
frank26080115 0:bf7b9fba3924 83
frank26080115 0:bf7b9fba3924 84
frank26080115 0:bf7b9fba3924 85 #if (USEDI2CDEV == 0)
frank26080115 0:bf7b9fba3924 86 /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/
frank26080115 0:bf7b9fba3924 87 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 88 * @brief Main I2C0 interrupt handler sub-routine
frank26080115 0:bf7b9fba3924 89 * @param[in] None
frank26080115 0:bf7b9fba3924 90 * @return None
frank26080115 0:bf7b9fba3924 91 **********************************************************************/
frank26080115 0:bf7b9fba3924 92 void I2C0_IRQHandler(void){
frank26080115 0:bf7b9fba3924 93 // just call std int handler
frank26080115 0:bf7b9fba3924 94 I2C_MasterHandler(I2CDEV);
frank26080115 0:bf7b9fba3924 95 if (I2C_MasterTransferComplete(I2CDEV)){
frank26080115 0:bf7b9fba3924 96 complete = SET;
frank26080115 0:bf7b9fba3924 97 }
frank26080115 0:bf7b9fba3924 98 }
frank26080115 0:bf7b9fba3924 99 #elif (USEDI2CDEV == 2)
frank26080115 0:bf7b9fba3924 100 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 101 * @brief Main I2C2 interrupt handler sub-routine
frank26080115 0:bf7b9fba3924 102 * @param[in] None
frank26080115 0:bf7b9fba3924 103 * @return None
frank26080115 0:bf7b9fba3924 104 **********************************************************************/
frank26080115 0:bf7b9fba3924 105 void I2C2_IRQHandler(void){
frank26080115 0:bf7b9fba3924 106 // just call std int handler
frank26080115 0:bf7b9fba3924 107 I2C_MasterHandler(I2CDEV);
frank26080115 0:bf7b9fba3924 108 if (I2C_MasterTransferComplete(I2CDEV)){
frank26080115 0:bf7b9fba3924 109 complete = SET;
frank26080115 0:bf7b9fba3924 110 }
frank26080115 0:bf7b9fba3924 111 }
frank26080115 0:bf7b9fba3924 112 #endif
frank26080115 0:bf7b9fba3924 113
frank26080115 0:bf7b9fba3924 114 /*-------------------------PRIVATE FUNCTIONS------------------------------*/
frank26080115 0:bf7b9fba3924 115 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 116 * @brief Print Welcome menu
frank26080115 0:bf7b9fba3924 117 * @param[in] none
frank26080115 0:bf7b9fba3924 118 * @return None
frank26080115 0:bf7b9fba3924 119 **********************************************************************/
frank26080115 0:bf7b9fba3924 120 void print_menu(void)
frank26080115 0:bf7b9fba3924 121 {
frank26080115 0:bf7b9fba3924 122 _DBG_(menu1);
frank26080115 0:bf7b9fba3924 123 }
frank26080115 0:bf7b9fba3924 124
frank26080115 0:bf7b9fba3924 125
frank26080115 0:bf7b9fba3924 126 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 127 * @brief A subroutine that will be called if there's any error
frank26080115 0:bf7b9fba3924 128 * on I2C operation
frank26080115 0:bf7b9fba3924 129 * @param[in] ErrorCode Error Code Input
frank26080115 0:bf7b9fba3924 130 * @return None
frank26080115 0:bf7b9fba3924 131 **********************************************************************/
frank26080115 0:bf7b9fba3924 132 void Error_Loop(uint8_t ErrorCode)
frank26080115 0:bf7b9fba3924 133 {
frank26080115 0:bf7b9fba3924 134 /*
frank26080115 0:bf7b9fba3924 135 * Insert your code here...
frank26080115 0:bf7b9fba3924 136 */
frank26080115 0:bf7b9fba3924 137 while(1);
frank26080115 0:bf7b9fba3924 138 }
frank26080115 0:bf7b9fba3924 139
frank26080115 0:bf7b9fba3924 140
frank26080115 0:bf7b9fba3924 141 /*-------------------------MAIN FUNCTION------------------------------*/
frank26080115 0:bf7b9fba3924 142 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 143 * @brief c_entry: Main program body
frank26080115 0:bf7b9fba3924 144 * @param[in] None
frank26080115 0:bf7b9fba3924 145 * @return int
frank26080115 0:bf7b9fba3924 146 **********************************************************************/
frank26080115 0:bf7b9fba3924 147 int c_entry(void)
frank26080115 0:bf7b9fba3924 148 {
frank26080115 0:bf7b9fba3924 149 uint8_t tmpchar[2] = {0, 0};
frank26080115 0:bf7b9fba3924 150 __IO FlagStatus exitflag;
frank26080115 0:bf7b9fba3924 151 PINSEL_CFG_Type PinCfg;
frank26080115 0:bf7b9fba3924 152 I2C_M_SETUP_Type transferCfg;
frank26080115 0:bf7b9fba3924 153 uint8_t SC16IS_RegStat;
frank26080115 0:bf7b9fba3924 154
frank26080115 0:bf7b9fba3924 155 #if (USEDI2CDEV == 0)
frank26080115 0:bf7b9fba3924 156 /* Disable I2C0 interrupt */
frank26080115 0:bf7b9fba3924 157 NVIC_DisableIRQ(I2C0_IRQn);
frank26080115 0:bf7b9fba3924 158 /* preemption = 1, sub-priority = 1 */
frank26080115 0:bf7b9fba3924 159 NVIC_SetPriority(I2C0_IRQn, ((0x01<<3)|0x01));
frank26080115 0:bf7b9fba3924 160 #elif (USEDI2CDEV == 2)
frank26080115 0:bf7b9fba3924 161 /* Disable I2C2 interrupt */
frank26080115 0:bf7b9fba3924 162 NVIC_DisableIRQ(I2C2_IRQn);
frank26080115 0:bf7b9fba3924 163 /* preemption = 1, sub-priority = 1 */
frank26080115 0:bf7b9fba3924 164 NVIC_SetPriority(I2C2_IRQn, ((0x01<<3)|0x01));
frank26080115 0:bf7b9fba3924 165 #endif
frank26080115 0:bf7b9fba3924 166
frank26080115 0:bf7b9fba3924 167 /* Initialize debug via UART0
frank26080115 0:bf7b9fba3924 168 * – 115200bps
frank26080115 0:bf7b9fba3924 169 * – 8 data bit
frank26080115 0:bf7b9fba3924 170 * – No parity
frank26080115 0:bf7b9fba3924 171 * – 1 stop bit
frank26080115 0:bf7b9fba3924 172 * – No flow control
frank26080115 0:bf7b9fba3924 173 */
frank26080115 0:bf7b9fba3924 174 debug_frmwrk_init();
frank26080115 0:bf7b9fba3924 175
frank26080115 0:bf7b9fba3924 176 // print welcome screen
frank26080115 0:bf7b9fba3924 177 print_menu();
frank26080115 0:bf7b9fba3924 178
frank26080115 0:bf7b9fba3924 179 /*
frank26080115 0:bf7b9fba3924 180 * Init I2C pin connect
frank26080115 0:bf7b9fba3924 181 */
frank26080115 0:bf7b9fba3924 182 PinCfg.OpenDrain = 0;
frank26080115 0:bf7b9fba3924 183 PinCfg.Pinmode = 0;
frank26080115 0:bf7b9fba3924 184 #if (USEDI2CDEV == 0)
frank26080115 0:bf7b9fba3924 185 PinCfg.Funcnum = 1;
frank26080115 0:bf7b9fba3924 186 PinCfg.Pinnum = 27;
frank26080115 0:bf7b9fba3924 187 PinCfg.Portnum = 0;
frank26080115 0:bf7b9fba3924 188 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 189 PinCfg.Pinnum = 28;
frank26080115 0:bf7b9fba3924 190 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 191 #elif (USEDI2CDEV == 2)
frank26080115 0:bf7b9fba3924 192 PinCfg.Funcnum = 2;
frank26080115 0:bf7b9fba3924 193 PinCfg.Pinnum = 10;
frank26080115 0:bf7b9fba3924 194 PinCfg.Portnum = 0;
frank26080115 0:bf7b9fba3924 195 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 196 PinCfg.Pinnum = 11;
frank26080115 0:bf7b9fba3924 197 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 198 #endif
frank26080115 0:bf7b9fba3924 199
frank26080115 0:bf7b9fba3924 200 /* I2C block ------------------------------------------------------------------- */
frank26080115 0:bf7b9fba3924 201 // Initialize I2C peripheral
frank26080115 0:bf7b9fba3924 202 I2C_Init(I2CDEV, 100000);
frank26080115 0:bf7b9fba3924 203
frank26080115 0:bf7b9fba3924 204 /* Enable I2C1 operation */
frank26080115 0:bf7b9fba3924 205 I2C_Cmd(I2CDEV, ENABLE);
frank26080115 0:bf7b9fba3924 206
frank26080115 0:bf7b9fba3924 207 // test
frank26080115 0:bf7b9fba3924 208 complete = RESET;
frank26080115 0:bf7b9fba3924 209 transferCfg.sl_addr7bit = SLVADDR;
frank26080115 0:bf7b9fba3924 210 transferCfg.tx_data = NULL;
frank26080115 0:bf7b9fba3924 211 transferCfg.tx_length = 0;
frank26080115 0:bf7b9fba3924 212 transferCfg.rx_data = &SC16IS_RegStat;
frank26080115 0:bf7b9fba3924 213 transferCfg.rx_length = 1;
frank26080115 0:bf7b9fba3924 214 transferCfg.retransmissions_max = 2;
frank26080115 0:bf7b9fba3924 215 I2C_MasterTransferData(I2CDEV, &transferCfg, I2C_TRANSFER_INTERRUPT);
frank26080115 0:bf7b9fba3924 216 while (complete == RESET);
frank26080115 0:bf7b9fba3924 217
frank26080115 0:bf7b9fba3924 218 /* Configure SC16IS750 ---------------------------------------------------------- */
frank26080115 0:bf7b9fba3924 219 /* First, send some command to reset SC16IS740 chip via I2C bus interface */
frank26080115 0:bf7b9fba3924 220 complete = RESET;
frank26080115 0:bf7b9fba3924 221 transferCfg.sl_addr7bit = SLVADDR;
frank26080115 0:bf7b9fba3924 222 transferCfg.tx_data = (uint8_t *)iocon_cfg;
frank26080115 0:bf7b9fba3924 223 transferCfg.tx_length = sizeof(iocon_cfg);
frank26080115 0:bf7b9fba3924 224 transferCfg.rx_data = NULL;
frank26080115 0:bf7b9fba3924 225 transferCfg.rx_length = 0;
frank26080115 0:bf7b9fba3924 226 transferCfg.retransmissions_max = 2;
frank26080115 0:bf7b9fba3924 227 I2C_MasterTransferData(I2CDEV, &transferCfg, I2C_TRANSFER_INTERRUPT);
frank26080115 0:bf7b9fba3924 228 while (complete == RESET);
frank26080115 0:bf7b9fba3924 229
frank26080115 0:bf7b9fba3924 230 complete = RESET;
frank26080115 0:bf7b9fba3924 231 transferCfg.sl_addr7bit = SLVADDR;
frank26080115 0:bf7b9fba3924 232 transferCfg.tx_data = (uint8_t *)iodir_cfg;
frank26080115 0:bf7b9fba3924 233 transferCfg.tx_length = sizeof(iodir_cfg);
frank26080115 0:bf7b9fba3924 234 transferCfg.rx_data = NULL;
frank26080115 0:bf7b9fba3924 235 transferCfg.rx_length = 0;
frank26080115 0:bf7b9fba3924 236 transferCfg.retransmissions_max = 2;
frank26080115 0:bf7b9fba3924 237 I2C_MasterTransferData(I2CDEV, &transferCfg, I2C_TRANSFER_INTERRUPT);
frank26080115 0:bf7b9fba3924 238 while (complete == RESET);
frank26080115 0:bf7b9fba3924 239
frank26080115 0:bf7b9fba3924 240 complete = RESET;
frank26080115 0:bf7b9fba3924 241 transferCfg.sl_addr7bit = SLVADDR;
frank26080115 0:bf7b9fba3924 242 transferCfg.tx_data = (uint8_t *)iostate_cfg_0;
frank26080115 0:bf7b9fba3924 243 transferCfg.tx_length = sizeof(iostate_cfg_0);
frank26080115 0:bf7b9fba3924 244 transferCfg.rx_data = NULL;
frank26080115 0:bf7b9fba3924 245 transferCfg.rx_length = 0;
frank26080115 0:bf7b9fba3924 246 transferCfg.retransmissions_max = 2;
frank26080115 0:bf7b9fba3924 247 I2C_MasterTransferData(I2CDEV, &transferCfg, I2C_TRANSFER_INTERRUPT);
frank26080115 0:bf7b9fba3924 248 while (complete == RESET);
frank26080115 0:bf7b9fba3924 249
frank26080115 0:bf7b9fba3924 250
frank26080115 0:bf7b9fba3924 251 /* Validate value of SC16IS750 register ------------------------------------------ */
frank26080115 0:bf7b9fba3924 252 /* This section will dump out value of register that set through I2C bus */
frank26080115 0:bf7b9fba3924 253 complete = RESET;
frank26080115 0:bf7b9fba3924 254 transferCfg.sl_addr7bit = SLVADDR;
frank26080115 0:bf7b9fba3924 255 transferCfg.tx_data = NULL; //(uint8_t *)iocon_cfg;
frank26080115 0:bf7b9fba3924 256 transferCfg.tx_length = 0;//1;
frank26080115 0:bf7b9fba3924 257 transferCfg.rx_data = &SC16IS_RegStat;
frank26080115 0:bf7b9fba3924 258 transferCfg.rx_length = 1;
frank26080115 0:bf7b9fba3924 259 transferCfg.retransmissions_max = 2;
frank26080115 0:bf7b9fba3924 260 I2C_MasterTransferData(I2CDEV, &transferCfg, I2C_TRANSFER_INTERRUPT);
frank26080115 0:bf7b9fba3924 261 while (complete == RESET);
frank26080115 0:bf7b9fba3924 262
frank26080115 0:bf7b9fba3924 263 complete = RESET;
frank26080115 0:bf7b9fba3924 264 transferCfg.sl_addr7bit = SLVADDR;
frank26080115 0:bf7b9fba3924 265 transferCfg.tx_data = (uint8_t *)iodir_cfg;
frank26080115 0:bf7b9fba3924 266 transferCfg.tx_length = 1;
frank26080115 0:bf7b9fba3924 267 transferCfg.rx_data = &SC16IS_RegStat;
frank26080115 0:bf7b9fba3924 268 transferCfg.rx_length = 1;
frank26080115 0:bf7b9fba3924 269 transferCfg.retransmissions_max = 2;
frank26080115 0:bf7b9fba3924 270 I2C_MasterTransferData(I2CDEV, &transferCfg, I2C_TRANSFER_INTERRUPT);
frank26080115 0:bf7b9fba3924 271 while (complete == RESET);
frank26080115 0:bf7b9fba3924 272
frank26080115 0:bf7b9fba3924 273 complete = RESET;
frank26080115 0:bf7b9fba3924 274 transferCfg.sl_addr7bit = SLVADDR;
frank26080115 0:bf7b9fba3924 275 transferCfg.tx_data = (uint8_t *)iostate_cfg_0;
frank26080115 0:bf7b9fba3924 276 transferCfg.tx_length = 1;
frank26080115 0:bf7b9fba3924 277 transferCfg.rx_data = &SC16IS_RegStat;
frank26080115 0:bf7b9fba3924 278 transferCfg.rx_length = 1;
frank26080115 0:bf7b9fba3924 279 transferCfg.retransmissions_max = 2;
frank26080115 0:bf7b9fba3924 280 I2C_MasterTransferData(I2CDEV, &transferCfg, I2C_TRANSFER_INTERRUPT);
frank26080115 0:bf7b9fba3924 281 while (complete == RESET);
frank26080115 0:bf7b9fba3924 282
frank26080115 0:bf7b9fba3924 283
frank26080115 0:bf7b9fba3924 284 // Reset exit flag
frank26080115 0:bf7b9fba3924 285 exitflag = RESET;
frank26080115 0:bf7b9fba3924 286
frank26080115 0:bf7b9fba3924 287 /* Read some data from the buffer */
frank26080115 0:bf7b9fba3924 288 while (exitflag == RESET){
frank26080115 0:bf7b9fba3924 289
frank26080115 0:bf7b9fba3924 290 while((tmpchar[0] = _DG) == 0);
frank26080115 0:bf7b9fba3924 291
frank26080115 0:bf7b9fba3924 292 if (tmpchar[0] == 27){
frank26080115 0:bf7b9fba3924 293 /* ESC key, set exit flag */
frank26080115 0:bf7b9fba3924 294 _DBG_(menu2);
frank26080115 0:bf7b9fba3924 295 exitflag = SET;
frank26080115 0:bf7b9fba3924 296 }
frank26080115 0:bf7b9fba3924 297 else if (tmpchar[0] == 'r'){
frank26080115 0:bf7b9fba3924 298 print_menu();
frank26080115 0:bf7b9fba3924 299 }
frank26080115 0:bf7b9fba3924 300 else{
frank26080115 0:bf7b9fba3924 301 if (tmpchar[0] == '1'){
frank26080115 0:bf7b9fba3924 302 // LEDs are ON now...
frank26080115 0:bf7b9fba3924 303 transferCfg.sl_addr7bit = SLVADDR;
frank26080115 0:bf7b9fba3924 304 transferCfg.tx_data = (uint8_t *)iostate_cfg_0;
frank26080115 0:bf7b9fba3924 305 transferCfg.tx_length = sizeof(iostate_cfg_0);
frank26080115 0:bf7b9fba3924 306 transferCfg.rx_data = NULL;
frank26080115 0:bf7b9fba3924 307 transferCfg.rx_length = 0;
frank26080115 0:bf7b9fba3924 308 transferCfg.retransmissions_max = 2;
frank26080115 0:bf7b9fba3924 309 if (I2C_MasterTransferData(I2CDEV, &transferCfg, I2C_TRANSFER_POLLING) \
frank26080115 0:bf7b9fba3924 310 == ERROR){
frank26080115 0:bf7b9fba3924 311 Error_Loop(transferCfg.status);
frank26080115 0:bf7b9fba3924 312 }
frank26080115 0:bf7b9fba3924 313 }
frank26080115 0:bf7b9fba3924 314 else if (tmpchar[0] == '2')
frank26080115 0:bf7b9fba3924 315 {
frank26080115 0:bf7b9fba3924 316 // LEDs are OFF now...
frank26080115 0:bf7b9fba3924 317 transferCfg.sl_addr7bit = SLVADDR;
frank26080115 0:bf7b9fba3924 318 transferCfg.tx_data = (uint8_t *)iostate_cfg_1;
frank26080115 0:bf7b9fba3924 319 transferCfg.tx_length = sizeof(iostate_cfg_1);
frank26080115 0:bf7b9fba3924 320 transferCfg.rx_data = NULL;
frank26080115 0:bf7b9fba3924 321 transferCfg.rx_length = 0;
frank26080115 0:bf7b9fba3924 322 transferCfg.retransmissions_max = 2;
frank26080115 0:bf7b9fba3924 323 if (I2C_MasterTransferData(I2CDEV, &transferCfg, I2C_TRANSFER_POLLING) \
frank26080115 0:bf7b9fba3924 324 == ERROR){
frank26080115 0:bf7b9fba3924 325 Error_Loop(transferCfg.status);
frank26080115 0:bf7b9fba3924 326 }
frank26080115 0:bf7b9fba3924 327 }
frank26080115 0:bf7b9fba3924 328 /* Then Echo it back */
frank26080115 0:bf7b9fba3924 329 _DBG_(tmpchar);
frank26080115 0:bf7b9fba3924 330 }
frank26080115 0:bf7b9fba3924 331 }
frank26080115 0:bf7b9fba3924 332
frank26080115 0:bf7b9fba3924 333 // wait for current transmission complete - THR must be empty
frank26080115 0:bf7b9fba3924 334 while (UART_CheckBusy(LPC_UART0) == SET);
frank26080115 0:bf7b9fba3924 335
frank26080115 0:bf7b9fba3924 336 // DeInitialize UART0 peripheral
frank26080115 0:bf7b9fba3924 337 UART_DeInit(LPC_UART0);
frank26080115 0:bf7b9fba3924 338 I2C_DeInit(I2CDEV);
frank26080115 0:bf7b9fba3924 339
frank26080115 0:bf7b9fba3924 340 /* Loop forever */
frank26080115 0:bf7b9fba3924 341 while(1);
frank26080115 0:bf7b9fba3924 342 return 1;
frank26080115 0:bf7b9fba3924 343 }
frank26080115 0:bf7b9fba3924 344
frank26080115 0:bf7b9fba3924 345 /* With ARM and GHS toolsets, the entry point is main() - this will
frank26080115 0:bf7b9fba3924 346 allow the linker to generate wrapper code to setup stacks, allocate
frank26080115 0:bf7b9fba3924 347 heap area, and initialize and copy code and data segments. For GNU
frank26080115 0:bf7b9fba3924 348 toolsets, the entry point is through __start() in the crt0_gnu.asm
frank26080115 0:bf7b9fba3924 349 file, and that startup code will setup stacks and data */
frank26080115 0:bf7b9fba3924 350 int main(void)
frank26080115 0:bf7b9fba3924 351 {
frank26080115 0:bf7b9fba3924 352 return c_entry();
frank26080115 0:bf7b9fba3924 353 }
frank26080115 0:bf7b9fba3924 354
frank26080115 0:bf7b9fba3924 355
frank26080115 0:bf7b9fba3924 356 #ifdef DEBUG
frank26080115 0:bf7b9fba3924 357 /*******************************************************************************
frank26080115 0:bf7b9fba3924 358 * @brief Reports the name of the source file and the source line number
frank26080115 0:bf7b9fba3924 359 * where the CHECK_PARAM error has occurred.
frank26080115 0:bf7b9fba3924 360 * @param[in] file Pointer to the source file name
frank26080115 0:bf7b9fba3924 361 * @param[in] line assert_param error line source number
frank26080115 0:bf7b9fba3924 362 * @return None
frank26080115 0:bf7b9fba3924 363 *******************************************************************************/
frank26080115 0:bf7b9fba3924 364 void check_failed(uint8_t *file, uint32_t line)
frank26080115 0:bf7b9fba3924 365 {
frank26080115 0:bf7b9fba3924 366 /* User can add his own implementation to report the file name and line number,
frank26080115 0:bf7b9fba3924 367 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
frank26080115 0:bf7b9fba3924 368
frank26080115 0:bf7b9fba3924 369 /* Infinite loop */
frank26080115 0:bf7b9fba3924 370 while(1);
frank26080115 0:bf7b9fba3924 371 }
frank26080115 0:bf7b9fba3924 372 #endif
frank26080115 0:bf7b9fba3924 373
frank26080115 0:bf7b9fba3924 374 /*
frank26080115 0:bf7b9fba3924 375 * @}
frank26080115 0:bf7b9fba3924 376 */