/*********************************************************************//** * @brief Print buffer data * @param[in] buff Buffer address * size Buffer size * * @return None **********************************************************************/ void Buffer_Print(uint8_t* buff, uint32_t size) { uint32_t i = 0; for (i = 0; i < size; i++) { if (i%10 == 0) { _DBG_("");_DBG(" "); } else _DBG(", "); _DBH(buff[i]); if( i == size - 1) _DBG_(""); } _DBG_(""); }
/****************************************************************************** ** Main Function main() ******************************************************************************/ void c_entry (void) { uint8_t error = 0; st_Mci_CardId cidval; en_Mci_CardType cardType; debug_frmwrk_init(); _DBG_("");_DBG(mciCidCardMenu);_DBG_(""); #if MCI_DMA_ENABLED /* on DMA channel 0, source is memory, destination is MCI FIFO. */ /* On DMA channel 1, source is MCI FIFO, destination is memory. */ GPDMA_Init(); #endif /* For the SD card I tested, the minimum required block length is 512 */ /* For MMC, the restriction is loose, due to the variety of SD and MMC card support, ideally, the driver should read CSD register to find the right speed and block length for the card, and set them accordingly. In this driver example, it will support both MMC and SD cards, and it does read the information by send SEND_CSD to poll the card status, however, to simplify the example, it doesn't configure them accordingly based on the CSD register value. This is not intended to support all the SD and MMC cards. */ if(MCI_Init(BRD_MCI_POWERED_ACTIVE_LEVEL) != MCI_FUNC_OK) { _DBG_("MCI_Init FAILED"); while( 1 ); /* fatal error */ } cardType = MCI_GetCardType(); switch (cardType) { case MCI_SDHC_SDXC_CARD: _DBG_("Currently the SDXC/SDHC CARD ver2.0 is being used"); break; case MCI_SDSC_V2_CARD: _DBG_("Currently the SD CARD ver2.0 is being used"); break; case MCI_SDSC_V1_CARD: _DBG_("Currently the SD CARD ver1.0 is being used"); break; case MCI_MMC_CARD: _DBG_("Currently the MMC CARD is being used"); break; case MCI_CARD_UNKNOWN: _DBG_("No CARD is being plugged, Please check!!!"); error = 1; break; } if(error) while(1); if (MCI_GetCID(&cidval) != MCI_FUNC_OK) { _DBG_("Get CID Failed"); while ( 1 ); /* fatal error */ } else { _DBG("\n\r\t- Manufacture ID: ");_DBH32(cidval.MID);_DBG_(""); _DBG("\n\r\t- OEM/Application ID: ");_DBH32(cidval.OID);_DBG_(""); _DBG("\n\r\t- Product Name: ");_DBH(cidval.PNM_H);_DBH32_(cidval.PNM_L);_DBG_(""); _DBG("\n\r\t- Product Revision: ");_DBH32(cidval.PRV);_DBG_(""); _DBG("\n\r\t- Product Serial Number: ");_DBH32(cidval.PSN);_DBG_(""); _DBG("\n\r\t- Manufacturing Date: ");_DBH32(cidval.MDT);_DBG_(""); } while(1); }
/*********************************************************************//** * @brief Main I2C master and slave program body **********************************************************************/ int c_entry(void) { PINSEL_CFG_Type PinCfg; I2C_OWNSLAVEADDR_CFG_Type OwnSlavAdr; I2C_S_SETUP_Type transferSCfg; uint32_t tempp; uint8_t *pdat; // DeInit NVIC and SCBNVIC NVIC_DeInit(); NVIC_SCBDeInit(); /* Configure the NVIC Preemption Priority Bits: * two (2) bits of preemption priority, six (6) bits of sub-priority. * Since the Number of Bits used for Priority Levels is five (5), so the * actual bit number of sub-priority is three (3) */ NVIC_SetPriorityGrouping(0x05); // Set Vector table offset value #if (__RAM_MODE__==1) NVIC_SetVTOR(0x10000000); #else NVIC_SetVTOR(0x00000000); #endif /* Initialize debug */ debug_frmwrk_init(); print_menu(); /* I2C block ------------------------------------------------------------------- */ /* * Init I2C pin connect */ PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; #if ((USEDI2CDEV_S == 0)) PinCfg.Funcnum = 1; PinCfg.Pinnum = 27; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 28; PINSEL_ConfigPin(&PinCfg); #endif #if ((USEDI2CDEV_S == 2)) PinCfg.Funcnum = 2; PinCfg.Pinnum = 10; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 11; PINSEL_ConfigPin(&PinCfg); #endif // Initialize Slave I2C peripheral I2C_Init(I2CDEV_S, 100000); /* Set Own slave address for I2C device */ OwnSlavAdr.GeneralCallState = ENABLE; OwnSlavAdr.SlaveAddrChannel= 0; OwnSlavAdr.SlaveAddrMaskValue = 0xFF; OwnSlavAdr.SlaveAddr_7bit = I2CDEV_S_OWN_ADDR; I2C_SetOwnSlaveAddr(I2CDEV_S, &OwnSlavAdr); /* Enable Slave I2C operation */ I2C_Cmd(I2CDEV_S, ENABLE); _DBG_("Press '1' to start"); while (_DG != '1'); /* Reading -------------------------------------------------------- */ _DBG_("Start Reading..."); /* Initialize buffer */ Buffer_Init(0); /* Start I2C slave device first */ transferSCfg.tx_data = NULL; transferSCfg.tx_length = 0; transferSCfg.rx_data = Slave_Buf; transferSCfg.rx_length = sizeof(Slave_Buf); I2C_SlaveTransferData(I2CDEV_S, &transferSCfg, I2C_TRANSFER_POLLING); pdat = Slave_Buf; // Verify for (tempp = 0; tempp < sizeof(Slave_Buf); tempp++){ if (*pdat++ != tempp){ _DBG_("Verify error"); break; } } if (tempp == sizeof(Slave_Buf)){ _DBG_("Verify successfully"); } /* Transmit -------------------------------------------------------- */ _DBG_("Start Transmit..."); /* Initialize buffer */ Buffer_Init(1); /* Start I2C slave device first */ transferSCfg.tx_data = Slave_Buf; transferSCfg.tx_length = sizeof(Slave_Buf); transferSCfg.rx_data = NULL; transferSCfg.rx_length = 0; I2C_SlaveTransferData(I2CDEV_S, &transferSCfg, I2C_TRANSFER_POLLING); _DBG_("Complete!"); #if 1 /* Receive and transmit -------------------------------------------------------- */ _DBG_("Start Receive, wait for repeat start and transmit..."); /* Initialize buffer */ Buffer_Init(1); slave_test[0] = 0xAA; slave_test[1] = 0x55; /* Start I2C slave device first */ transferSCfg.tx_data = Slave_Buf; transferSCfg.tx_length = sizeof(Slave_Buf); transferSCfg.rx_data = slave_test; transferSCfg.rx_length = sizeof(slave_test); I2C_SlaveTransferData(I2CDEV_S, &transferSCfg, I2C_TRANSFER_POLLING); _DBG_("Receive Data:"); _DBH(slave_test[0]); _DBG_(""); _DBH(slave_test[1]); _DBG_(""); _DBG_("Complete!"); #endif /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { PINSEL_CFG_Type PinCfg; uint8_t idx,i; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); //print menu screen print_menu(); /* I2C block ------------------------------------------------------------------- */ /* * Init I2C pin connect */ PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Funcnum = 1; PinCfg.Pinnum = 27; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg);//SDA0 PinCfg.Pinnum = 28; PINSEL_ConfigPin(&PinCfg);//SCL0 // Initialize I2C peripheral I2C_Init(I2CDEV, 100000); /* Configure interrupt for I2C in NVIC of ARM core */ /* Disable I2C0 interrupt */ NVIC_DisableIRQ(I2C0_IRQn); /* preemption = 1, sub-priority = 0 */ NVIC_SetPriority(I2C0_IRQn, ((0x01<<3)|0x01)); //enable I2C interrupt I2C_IntCmd(LPC_I2C0, ENABLE); /* Enable I2C operation */ I2C_Cmd(I2CDEV, ENABLE); while(1) { idx=0;count=0; while(idx<2) { if(idx==0) { _DBG_("\n\rEnter monitor buffer size: "); } idx++; switch(_DG) { case '0': count=(count<<4)|0x00;break; case '1': count=(count<<4)|0x01;break; case '2': count=(count<<4)|0x02;break; case '3': count=(count<<4)|0x03;break; case '4': count=(count<<4)|0x04;break; case '5': count=(count<<4)|0x05;break; case '6': count=(count<<4)|0x06;break; case '7': count=(count<<4)|0x07;break; case '8': count=(count<<4)|0x08;break; case '9': count=(count<<4)|0x09;break; case 'a': count=(count<<4)|0x0A;break; case 'A': count=(count<<4)|0x0A;break; case 'b': count=(count<<4)|0x0B;break; case 'B': count=(count<<4)|0x0B;break; case 'c': count=(count<<4)|0x0C;break; case 'C': count=(count<<4)|0x0C;break; case 'd': count=(count<<4)|0x0D;break; case 'D': count=(count<<4)|0x0D;break; case 'e': count=(count<<4)|0x0E;break; case 'E': count=(count<<4)|0x0E;break; case 'f': count=(count<<4)|0x0F;break; case 'F': count=(count<<4)|0x0F;break; default: idx=0;count=0;break; } if(idx==2) { if(count>BUFFER_SIZE) { _DBG_("invalid! The size is bigger than ");_DBH(BUFFER_SIZE); idx=0;count=0; } else _DBH(count); } } //Configure I2C in monitor mode I2C_MonitorModeConfig(I2CDEV,(uint32_t)I2C_MONITOR_CFG_MATCHALL, ENABLE); I2C_MonitorModeCmd(I2CDEV, ENABLE); _DBG_("\n\rStart monitoring I2C bus..."); while(done==FALSE); done=FALSE; _DBG_("done!"); for(i=0;i<count;i++) { if((i%16)==0) _DBG_(""); _DBH(buffer[i]);_DBC(0x20); buffer[i]=0; } } return 1; }