void Chip_ADS1248_SelfOffsetCal(uint8_t chip) { Chip_SSP_DATA_SETUP_T xf_setup; xf_setup.length = BUFFER_SIZE; xf_setup.rx_cnt = 0; xf_setup.tx_cnt = 0; xf_setup.rx_data = rx_buf; xf_setup.tx_data = tx_buf; Chip_ADS1248_BufferInit(); tx_buf[0] = SELFOCAL; if(chip == CHIP_U1) { Chip_GPIO_SetPinOutLow(LPC_GPIO, ADS_nSSEL0); //Chip select Low(0) Chip_SSP_RWFrames_Blocking(ADS_SSP, &xf_setup); Chip_GPIO_SetPinOutHigh(LPC_GPIO, ADS_nSSEL0); //Chip select High(1) } else { Chip_GPIO_SetPinOutLow(LPC_GPIO, ADS_nSSEL1); //Chip select Low(0) Chip_SSP_RWFrames_Blocking(ADS_SSP, &xf_setup); Chip_GPIO_SetPinOutHigh(LPC_GPIO, ADS_nSSEL1); //Chip select High(1) } return; }
void ApagarLed(void) { Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT,0,14); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT,1,11); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT,1,12); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT,5,2); }
uint8_t Chip_ADS1248_ReadRegister(uint8_t chip, uint8_t address) { Chip_SSP_DATA_SETUP_T xf_setup; xf_setup.length = BUFFER_SIZE; xf_setup.rx_cnt = 0; xf_setup.tx_cnt = 0; xf_setup.rx_data = rx_buf; xf_setup.tx_data = tx_buf; Chip_ADS1248_BufferInit(); tx_buf[0] = (RREG | address); //Register address 0010 rrrr, 'r' being register address tx_buf[1] = 0; //Num_of_bytes - 1 if(chip == CHIP_U1) { Chip_GPIO_SetPinOutLow(LPC_GPIO, ADS_nSSEL0); //Chip select Low(0) Chip_SSP_RWFrames_Blocking(ADS_SSP, &xf_setup); Chip_GPIO_SetPinOutHigh(LPC_GPIO, ADS_nSSEL0); //Chip select High(1) } else { Chip_GPIO_SetPinOutLow(LPC_GPIO, ADS_nSSEL1); //Chip select Low(0) Chip_SSP_RWFrames_Blocking(ADS_SSP, &xf_setup); Chip_GPIO_SetPinOutHigh(LPC_GPIO, ADS_nSSEL1); //Chip select High(1) } return rx_buf[2]; //during transmission 2 rcv. bytes are junk, third is the reg. value }
void Chip_ADS1248_WriteRegister(uint8_t chip, uint8_t address, uint8_t value) { Chip_SSP_DATA_SETUP_T xf_setup; xf_setup.length = BUFFER_SIZE; xf_setup.rx_cnt = 0; xf_setup.tx_cnt = 0; xf_setup.rx_data = rx_buf; xf_setup.tx_data = tx_buf; Chip_ADS1248_BufferInit(); tx_buf[0] = (WREG | address); //Register address 0010 rrrr, 'r' being register address tx_buf[1] = 0; //Num_of_bytes - 1 tx_buf[2] = value; //Register value if(chip == CHIP_U1) { Chip_GPIO_SetPinOutLow(LPC_GPIO, ADS_nSSEL0); //Chip select Low(0) Chip_SSP_RWFrames_Blocking(ADS_SSP, &xf_setup); Chip_GPIO_SetPinOutHigh(LPC_GPIO, ADS_nSSEL0); //Chip select High(1) } else { Chip_GPIO_SetPinOutLow(LPC_GPIO, ADS_nSSEL1); //Chip select Low(0) Chip_SSP_RWFrames_Blocking(ADS_SSP, &xf_setup); Chip_GPIO_SetPinOutHigh(LPC_GPIO, ADS_nSSEL1); //Chip select High(1) } return; }
void InitHardware() { Chip_GPIO_WriteDirBit(LPC_GPIO, 0, 22, 1); //Led stick Chip_GPIO_WriteDirBit(LPC_GPIO, 0, 1, 1); //Puerto CE Chip_GPIO_SetPinOutLow(LPC_GPIO, 0, 1); //Puerto CE Chip_GPIO_SetPinOutLow(LPC_GPIO, 0, 22); }
void __attribute__ ((noinline)) i2c_init(void) { Chip_IOCON_PinSetMode(LPC_IOCON,IOCON_PIO0,PIN_MODE_INACTIVE); /* no pullup/-down */ Chip_IOCON_PinSetMode(LPC_IOCON,IOCON_PIO3,PIN_MODE_INACTIVE); /* no pullup/-down */ Chip_IOCON_PinEnableOpenDrainMode(LPC_IOCON, IOCON_PIO3); Chip_IOCON_PinEnableOpenDrainMode(LPC_IOCON, IOCON_PIO0); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 0, 3); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 0, 0); }
uint32_t PWMSetPeriod(uint8_t channel, uint32_t period) { if (channel > CHANNEL_C_TIMER_INDEX) { return 1; } if (eDVSMode != EDVS_MODE_INTERNAL && channel == 0) { return 1; // channel 0 taken for master/slave mode } LPC_TIMER_T * timer = halTimers[channel].timer; halTimers[channel].period = period; /** * If the period equal 0, the timer is disable and its outputs are set as GPIO and driven low. */ if (period == 0) { Chip_TIMER_DeInit(timer); //Stop the timer Chip_TIMER_SetMatch(timer, 2, 0); halTimers[channel].enabled[0] = DISABLE; halTimers[channel].enabled[1] = DISABLE; Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, halTimers[channel].portGpio[0], halTimers[channel].pinGpio[0]); Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, halTimers[channel].portGpio[1], halTimers[channel].pinGpio[1]); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, halTimers[channel].portGpio[0], halTimers[channel].pinGpio[0]); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, halTimers[channel].portGpio[1], halTimers[channel].pinGpio[1]); Chip_SCU_PinMuxSet(halTimers[channel].port[0], halTimers[channel].pin[0], halTimers[channel].gpioMode[0]); Chip_SCU_PinMuxSet(halTimers[channel].port[1], halTimers[channel].pin[1], halTimers[channel].gpioMode[1]); } else { /** * The channel match 2 is used as the controller of the base frequency. * When there is a match on this channel, the timer is reset and the external match bit * is set to 1. * The M0 core is looking for this change and it sets the output of the channels to high. */ Chip_TIMER_Init(timer); Chip_TIMER_Disable(timer); Chip_TIMER_Reset(timer); /** * The Main clock is running at 192Mhz so set the Prescaler in order to have * a 1 Mhz timer. Timer_CLK = Main_CLK/ (PR+1) */ Chip_TIMER_PrescaleSet(timer, 191); Chip_TIMER_ResetOnMatchEnable(timer, 2); Chip_TIMER_StopOnMatchDisable(timer, 2); Chip_TIMER_MatchDisableInt(timer, 2); Chip_TIMER_SetMatch(timer, 2, period); //Reconfigure match channels! if (halTimers[channel].enabled[0]) { PWMSetWidth(channel, 0, halTimers[channel].witdh[0]); } if (halTimers[channel].enabled[1]) { PWMSetWidth(channel, 1, halTimers[channel].witdh[1]); } Chip_TIMER_ExtMatchControlSet(timer, 0, TIMER_EXTMATCH_SET, 2); // Clear interrupt pending timer->IR = 0xFFFFFFFF; Chip_TIMER_Enable(timer); } return 0; }
/*Función para apagar uno o más leds dentro del led RGB.*/ void RGBoff (edu_CIAA_ledRGB *rgb){ if (rgb->red == 0){ Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, LED_RGB_R_GPIO_NUMBER, LED_RGB_R_GPIO_PIN); } if (rgb->green == 0){ Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, LED_RGB_G_GPIO_NUMBER, LED_RGB_G_GPIO_PIN); } if (rgb->blue == 0){ Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, LED_RGB_B_GPIO_NUMBER, LED_RGB_B_GPIO_PIN); } }
/*Función para apagar alguno de los leds 1, 2 y 3. Qué led se apaga * depende del parámetro "led", que recibe la función.*/ void LEDoff(uint8_t led){ switch(led){ case LED_ROJO: // Led 1 Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, LED_1_GPIO_NUMBER, LED_1_GPIO_PIN); break; case LED_AMARILLO: // Led 2 Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, LED_2_GPIO_NUMBER, LED_2_GPIO_PIN); break; case LED_VERDE: // Led 3 Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, LED_3_GPIO_NUMBER, LED_3_GPIO_PIN); break; } }
void InvierteLed(uint8_t led) { if (led==1) { Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, 0, 14); } if (led==2) { Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, 1, 11); } if (led==3) { Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, 1, 12); } if (led==4) { Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, 5, 0); } if (led==5) { Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, 5, 1); } if (led==6) { Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, 5, 2); } if (led==0) { Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 0, 14); Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, 1, 11); Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, 1, 12); Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, 5, 0); Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, 5, 1); Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, 5, 2); } }
/*Apaga leds como parametro puerto y pin*/ void ApagarLed(int PIN){ int puerto; int pin=PIN; /**/ switch(pin){ case 14 : puerto=0; break; case 11 : case 12 : puerto=1; break; case 0 : case 1 : case 2 : puerto=5; break; /* optional */ /* you can have any number of case statements */ default : /* Optional */ break; } Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT,puerto,pin); }
void Board_GPIOs_writeValue(int32_t gpioNumber,uint8_t value) { if(value) Chip_GPIO_SetPinOutHigh(LPC_GPIO_PORT, gpiosInfo[gpioNumber].gpio, gpiosInfo[gpioNumber].gpioBit); else Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, gpiosInfo[gpioNumber].gpio, gpiosInfo[gpioNumber].gpioBit); }
uint32_t PWMSetWidth(uint8_t channel, uint8_t output, uint32_t width) { if (output >= MAX_OUTPUTS || channel > CHANNEL_C_TIMER_INDEX) { return 1; } if (eDVSMode != EDVS_MODE_INTERNAL && channel == 0) { return 1; // channel 0 taken for master/slave mode } LPC_TIMER_T * timer = halTimers[channel].timer; halTimers[channel].witdh[output] = width; halTimers[channel].enabled[output] = ENABLE; /** * Since we have to use the Core M0 to overcome hardware limitations * when the width is 0 or bigger than the period of the wave, * the output is set as GPIO and driven accordingly. */ if (width == 0) { //Set GPIO Low Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, halTimers[channel].portGpio[output], halTimers[channel].pinGpio[output]); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, halTimers[channel].portGpio[output], halTimers[channel].pinGpio[output]); Chip_SCU_PinMuxSet(halTimers[channel].port[output], halTimers[channel].pin[output], halTimers[channel].gpioMode[output]); } else if (width >= timer->MR[2]) { //Set GPIO High Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, halTimers[channel].portGpio[output], halTimers[channel].pinGpio[output]); Chip_GPIO_SetPinOutHigh(LPC_GPIO_PORT, halTimers[channel].portGpio[output], halTimers[channel].pinGpio[output]); Chip_SCU_PinMuxSet(halTimers[channel].port[output], halTimers[channel].pin[output], halTimers[channel].gpioMode[output]); } else { Chip_TIMER_SetMatch(timer, halTimers[channel].timerChannel[output], width); Chip_SCU_PinMuxSet(halTimers[channel].port[output], halTimers[channel].pin[output], halTimers[channel].timerMode[output]); } return 0; }
static void initHardware(void) { Chip_SetupXtalClocking(); Chip_SYSCTL_SetFLASHAccess(FLASHTIM_100MHZ_CPU); SystemCoreClockUpdate(); /*====================[PARA MODULO RF]====================*/ Chip_GPIO_WriteDirBit(LPC_GPIO, CE_PIN, 1); //Puerto CE Chip_GPIO_SetPinOutLow(LPC_GPIO, CE_PIN); //Puerto CE InitSPI (); begin(); setPALevel(RF24_PA_LOW); openWritingPipe(&addresses2[0]); openReadingPipe(1,&addresses1[0]); //1Node: Transmite paquetes el tx por este pide (addres) startListening(); /*========================================================*/ // Board_Init(); // Board_LED_Set(0, false); SysTick_Config(SystemCoreClock/1000); //1000 ticks por segundo InitPWM_motores(0); //Función inicialización modulo PWM InitPWM_motores(1); //Función inicialización modulo PWM InitPWM_motores(2); //Función inicialización modulo PWM InitPWM_motores(3); //Función inicialización modulo PWM InitPWM0(); InitGPIO(0); //Llamo función para inicializar GPIO InitGPIO(1); //Llamo función para inicializar GPIO InitGPIO(2); //Llamo función para inicializar GPIO InitGPIO(3); //Llamo función para inicializar GPIO Stop_and_Default(0); //Condiciones iniciales Stop_and_Default(1); //Condiciones iniciales Stop_and_Default(2); //Condiciones iniciales Stop_and_Default(3); //Condiciones iniciales P2_6ER = 1; P2_7ER = 1; P2_8ER = 1; P2_6EF = 1; P2_7EF = 1; P2_8EF = 1; P0_15ER = 1; P0_16ER = 1; P2_9ER = 1; P0_15EF = 1; P0_16EF = 1; P2_9EF = 1; NVIC_SetPriority(EINT3_IRQn,1); //Le pongo la mayor prioridad a la interrupcion NVIC_EnableIRQ(EINT3_IRQn); }
void writeToSPI(int length) { spi.length = length; spi.rx_cnt = 0; spi.tx_cnt = 0; Chip_GPIO_SetPinOutLow(LPC_GPIO, CSN_PORT, CSN_PIN); Chip_SSP_RWFrames_Blocking(LPC_SSP1, &spi); Chip_GPIO_SetPinOutHigh(LPC_GPIO, CSN_PORT, CSN_PIN); }
void InicializarLEDS(){ Chip_GPIO_Init(LPC_GPIO_PORT); //Mapeo los ledsa los GPIOX.X y habilito pullup Chip_SCU_PinMux(2,0,MD_PUP,FUNC4); //mapea 2.0 a GPIO5[0] (RGB, R) Chip_SCU_PinMux(2,1,MD_PUP,FUNC4); //mapea 2.0 a GPIO5[1] (RGB, G) Chip_SCU_PinMux(2,2,MD_PUP,FUNC4); //mapea 2.0 a GPIO5[2] (RGB, B) Chip_SCU_PinMux(2,10,MD_PUP,FUNC0); //mapea 2.0 a GPIO0[14] (LED Amarillo) Chip_SCU_PinMux(2,11,MD_PUP,FUNC0); //mapea 2.0 a GPIO1[11] (LED Rojo) Chip_SCU_PinMux(2,12,MD_PUP,FUNC0); //mapea 2.0 a GPIO1[12] (LED Verde) //Direcciono los GPIOX.X Chip_GPIO_SetDir(LPC_GPIO_PORT, 5, (1<<0), 1); // !1 es SALIDA, LPC_GPIO_PORT Chip_GPIO_SetDir(LPC_GPIO_PORT, 5, (1<<1), 1); Chip_GPIO_SetDir(LPC_GPIO_PORT, 5, (1<<2), 1); Chip_GPIO_SetDir(LPC_GPIO_PORT, 0, (1<<14), 1); Chip_GPIO_SetDir(LPC_GPIO_PORT, 1, (1<<11), 1); Chip_GPIO_SetDir(LPC_GPIO_PORT, 1, (1<<12), 1); //Pongo en bajo las salidas GPIOX.X Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 5, 0); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 5, 1); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 5, 2); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 0, 14); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 1, 11); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 1, 12); }
void inicializarled() { Chip_GPIO_Init(LPC_GPIO_PORT); Chip_SCU_PinMux(2,0,MD_PUP,FUNC4); /* remapea P2_0 en GPIO5[0], LED0R y habilita el pull up*/ Chip_SCU_PinMux(2,1,MD_PUP,FUNC4); /* remapea P2_1 en GPIO5[1], LED0G y habilita el pull up */ Chip_SCU_PinMux(2,2,MD_PUP,FUNC4); /* remapea P2_2 en GPIO5[2], LED0B y habilita el pull up */ Chip_SCU_PinMux(2,10,MD_PUP,FUNC0); /* remapea P2_10 en GPIO0[14], LED1 y habilita el pull up */ Chip_SCU_PinMux(2,11,MD_PUP,FUNC0); /* remapea P2_11 en GPIO1[11], LED2 y habilita el pull up */ Chip_SCU_PinMux(2,12,MD_PUP,FUNC0); /* remapea P2_12 en GPIO1[12], LED3 y habilita el pull up */ Chip_GPIO_SetDir(LPC_GPIO_PORT,5,(1<<0)|(1<<1)|(1<<2),1); // Defino ls puertos como salidas Chip_GPIO_SetDir(LPC_GPIO_PORT,0,(1<<14),1); Chip_GPIO_SetDir(LPC_GPIO_PORT,1,(1<<11)|(1<<12),1); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT,5,0); // reseteo todos los leds Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT,5,1); // reseteo todos los leds Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT,5,2); // reseteo todos los leds Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT,0,14); // reseteo todos los leds Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT,1,11); // reseteo todos los leds Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT,1,14); // reseteo todos los leds }
void ApagarLEDS(){ Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 1, 12); //VERDE Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 0, 14); //ROJO Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 1, 11); //AMARILLO Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 5, 0); //R,G,B Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 5, 1); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 5, 2); }
int main(void) { uint32_t prompt = 0, rdCnt = 0; volatile bool start_trigger = false; #if defined (M0_SLAVE_PAUSE_AT_MAIN) // Pause execution until debugger attaches and modifies variable while (pause_at_main == 0) { } #endif init_g_vInitHardware(); // usb_g_vInit(); // init the interface SGPIO_spiInit(); // ipc_g_vInit(); // set direction of u4 Chip_SCU_PinMux(2, 10, SCU_MODE_PULLUP, SCU_MODE_FUNC0); Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 14); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 0, 14); //SysTick_Config(120000000/1000); // CS_Pin Chip_SCU_PinMux(0, 1, SCU_MODE_PULLUP, SCU_MODE_FUNC0); Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 1); Chip_GPIO_SetPinOutHigh(LPC_GPIO_PORT, 0, 1); // radar_g_vDefaultInit(); while (1) { // if (start_trigger) { // radar_mg_vPLLRampUp(); // radar_mg_vPLLActivateModulation(); // for (uint32_t i = 0; i < 40000000; i++) // ; // radar_mg_vPLLDeactivateModulation(); // radar_mg_vPLLRampDown(); // radar_mg_vPLLActivateModulation(); // for (uint32_t i = 0; i < 40000000; i++) // ; // radar_mg_vPLLDeactivateModulation(); // // } } while(1); }
/** * Methods */ void nRF24L01PInit(unsigned char transmitMode) { Chip_GPIO_SetPinOutHigh(LPC_GPIO, CSN_PORT, CSN_PIN); Chip_GPIO_SetPinDIROutput(LPC_GPIO, CSN_PORT, CSN_PIN); Chip_GPIO_SetPinOutLow(LPC_GPIO, NORDIC_CE_PORT, NORDIC_CE_PIN); Chip_GPIO_SetPinDIROutput(LPC_GPIO, NORDIC_CE_PORT, NORDIC_CE_PIN); Chip_GPIO_SetPinDIRInput(LPC_GPIO, NORDIC_IRQ_PORT, NORDIC_IRQ_PIN); nRF24L01P.mode = NRF24L01P_MODE_UNKNOWN; nRF24L01P.transmissionTimeout = -1; nRF24L01P.payloadsinTXFIFO = 0; RFdisable(); Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SSP1); Chip_SSP_Set_Mode(LPC_SSP1, SSP_MODE_MASTER); Chip_SSP_SetFormat(LPC_SSP1, SSP_BITS_8, SSP_FRAMEFORMAT_SPI, SSP_CLOCK_CPHA0_CPOL0); // 8-bit, ClockPhase = 0, ClockPolarity = 0 Chip_SSP_SetBitRate(LPC_SSP1, NRF24L01P_SPI_MAX_DATA_RATE / 2); // 2Mbit, 1/5th the maximum transfer rate for the SPI bus Chip_SSP_Enable(LPC_SSP1); RingBuffer_Init(&nordicTxBuffer, nordictxBufferArray, 1, TX_BUFFER_SIZE); memset(&spi, 0, sizeof(spi)); spi.tx_data = spiBufferTx; spi.rx_data = spiBufferRx; timerDelayUs(NRF24L01P_TIMING_Tundef2pd_us); // Wait for Power-on reset RFsetRegister(NRF24L01P_REG_CONFIG, 0); // Power Down RFsetRegister(NRF24L01P_REG_STATUS, NRF24L01P_STATUS_MAX_RT | NRF24L01P_STATUS_TX_DS | NRF24L01P_STATUS_RX_DR); // Clear any pending interrupts RFsetRegister(NRF24L01P_REG_FEATURE, NRF24L01P_EN_DYN_ACK | NRF24L01P_EN_ACK_PAY | NRF24L01P_EN_DPL); //Enabled no ack packages RFsetRegister(NRF24L01P_REG_DYNPD, NRF24L01P_DPL_P0); RFsetRegister(NRF24L01P_REG_RF_SETUP, 0); // Clear this register // // Setup default configuration // RFdisableAllRxPipes(); RFsetFrequency(DEFAULTNRF24L01P_RF_FREQUENCY); RFsetAirDataRate(DEFAULTNRF24L01P_DATARATE); RFsetRfOutputPower(DEFAULTNRF24L01P_TX_PWR); RFsetCrcWidth(DEFAULTNRF24L01P_CRC); RFsetTxAddress(DEFAULTNRF24L01P_ADDRESS, DEFAULTNRF24L01P_ADDRESS_WIDTH); RFsetRxAddress(DEFAULTNRF24L01P_ADDRESS, DEFAULTNRF24L01P_ADDRESS_WIDTH, NRF24L01P_PIPE_P0); RFenableAutoRetransmit(250, 3); RFdisableAutoAcknowledge(); RFenableAutoAcknowledge(NRF24L01P_PIPE_P0); RFsetTransferSize(DEFAULTNRF24L01P_TRANSFER_SIZE, NRF24L01P_PIPE_P0); nRF24L01P.mode = NRF24L01P_MODE_POWER_DOWN; if (transmitMode) { RFsetTransmitMode(); } else { RFsetReceiveMode(); } RFenable(); }
void manual_test() { updateMotorDutyCycle(0, 1); test_sd_card(); Chip_SCU_PinMuxSet(LED0_PORT, LED0_PIN, MD_PLN_FAST | FUNC0); // set P0.0 as output Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, LED0_PORT_GPIO, LED0_PIN_GPIO); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, LED0_PORT_GPIO, LED0_PIN_GPIO); for (;;) { timerDelayMs(1000); xprintf("Alive\n"); Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, LED0_PORT_GPIO, LED0_PIN_GPIO); } }
void Board_KEYBOARD_tick_ms(void) { if(keyboardInfo.enable==1) { switch(keyboardInfo.state) { case KEYBOARD_SCAN_STATE_START: { keyboardInfo.currentCol=0; keyboardInfo.state=KEYBOARD_SCAN_STATE_COL_LOW; break; } case KEYBOARD_SCAN_STATE_COL_LOW: { if(keyboardInfo.currentCol>=keyboardInfo.columns) { keyboardInfo.state=KEYBOARD_SCAN_STATE_START; } else { // set col low Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, keyboardColsPinInfo[keyboardInfo.currentCol].gpio, keyboardColsPinInfo[keyboardInfo.currentCol].gpioBit); keyboardInfo.state=KEYBOARD_SCAN_STATE_READ_ROWS; } break; } case KEYBOARD_SCAN_STATE_READ_ROWS: { // read rows int row; for(row=0; row<keyboardInfo.rows;row++) { int rowVal = Chip_GPIO_GetPinState(LPC_GPIO_PORT, keyboardRowsPinInfo[row].gpio, keyboardRowsPinInfo[row].gpioBit); keyboardInfo.stateMatrix[row][keyboardInfo.currentCol] = rowVal; } // set col high Chip_GPIO_SetPinOutHigh(LPC_GPIO_PORT, keyboardColsPinInfo[keyboardInfo.currentCol].gpio, keyboardColsPinInfo[keyboardInfo.currentCol].gpioBit); keyboardInfo.currentCol++; keyboardInfo.state=KEYBOARD_SCAN_STATE_COL_LOW; break; } } } }
uint8_t SPI_ReadWrite( uint8_t p) { uint8_t rxBuf; Chip_SSP_DATA_SETUP_T data; Chip_GPIO_SetPinOutLow(LPC_GPIO, TOUCH_E); data.rx_data=&rxBuf; data.tx_data=&p; data.length=1; data.rx_cnt = 0; data.tx_cnt = 0; Chip_SSP_RWFrames_Blocking(LPC_SSP0,&data); //Chip_GPIO_SetPinOutHigh(LPC_GPIO,TOUCH_E); return rxBuf; }
int main(void) { uint32_t fg_prev_result = 0; bool start_trigger=false; init_g_vInitHardware(); ipc_g_vInit(); adc_g_v_Init(); dma_g_v_DmaAdchsInit(); // adc_g_v_TriggerConversion(); Chip_SCU_PinMux(1, 13, SCU_MODE_PULLUP, SCU_MODE_FUNC0); Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 1, 6); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 1, 6); while (1) { // if(start_trigger){ // Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 1, 6); // Chip_GPIO_SetPinOutHigh(LPC_GPIO_PORT, 1, 6); // for(int i=0;i<10000;i++); // Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 1, 6); // for(int i=0;i<1000000;i++); // } if (dma_g_bGetDataReady()) { dma_g_vResetDataReady(); if (dsp_g_bProcessSignal()) { dma_g_v_DmaAdchsReInit(); // ipc_g_vSendMsg(); if (fg_prev_result != (uint32_t) dsp_g_f32GetTestFrequency()) { fg_prev_result = dsp_g_f32GetTestFrequency(); printf("Frequenz: %12f\r", dsp_g_f32GetTestFrequency()); } } } } }
int __attribute__ ((noinline)) main(void) { /* set systick and start systick interrupt */ SysTick_Config(SYS_CORE_CLOCK/1000UL*(unsigned long)SYS_TICK_PERIOD_IN_MS); /* turn on GPIO */ Chip_GPIO_Init(LPC_GPIO_PORT); /* disable SWCLK and SWDIO, after reset, boot code may activate this */ Chip_SWM_DisableFixedPin(2); Chip_SWM_DisableFixedPin(3); /* turn on IOCON */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON); /* turn on switch matrix */ Chip_SWM_Init(); /* activate analog comperator */ Chip_ACMP_Init(LPC_CMP); /* let LED on pin 4 of the DIP8 blink */ Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 2); for(;;) { Chip_GPIO_SetPinOutHigh(LPC_GPIO_PORT, 0, 2); delay_micro_seconds(500000UL); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 0, 2); delay_micro_seconds(500000UL); } /* enter sleep mode: Reduce from 1.4mA to 0.8mA with 12MHz */ while (1) { SCB->SCR |= (1UL << SCB_SCR_SLEEPONEXIT_Pos); /* enter sleep mode after interrupt */ Chip_PMU_SleepState(LPC_PMU); /* enter sleep mode now */ } }
void apagar_led (int led_n) { if (led_n==1) Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 0, 14 ); if (led_n==2) Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 1, 11 ); if (led_n==3) Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 1, 12 ); if (led_n==LED_ROJO ) Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, LED_RGB_PORT, LED_RGB_ROJO ); if (led_n==LED_VERDE ) Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, LED_RGB_PORT, LED_RGB_VERDE ); if (led_n==LED_AZUL ) Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, LED_RGB_PORT, LED_RGB_AZUL ); }
int ApagarLED(int LED){ switch (LED) { case VERDE: //VERDE Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 1, 12); break; case AMARILLO: //AMARILLO Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 1, 11); break; case ROJO: //ROJO Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 0, 14); break; case RGB: Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 5, 0); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 5, 1); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 5, 2); break; default: return 0; break; } return 1; }
/** \brief Main function * * This is the main entry point of the software. * * \returns 0 * * \remarks This function never returns. Return value is only to avoid compiler * warnings or errors. */ void InicializarLeds(void) { Chip_GPIO_Init(LPC_GPIO_PORT); Chip_SCU_PinMux(2,10,MD_PUP,FUNC0); Chip_SCU_PinMux(2,11,MD_PUP,FUNC0); Chip_SCU_PinMux(2,12,MD_PUP,FUNC0); Chip_GPIO_SetDir(LPC_GPIO_PORT,0,1<<14, 1); // 100000000000000 Chip_GPIO_SetDir(LPC_GPIO_PORT,1,(1<<11)|(1<<12), 1); Chip_SCU_PinMux(2,0,MD_PUP,FUNC4); Chip_SCU_PinMux(2,1,MD_PUP,FUNC4); Chip_SCU_PinMux(2,2,MD_PUP,FUNC4); Chip_GPIO_SetDir(LPC_GPIO_PORT,5,(1<<0)|(1<<1)|(1<<2), 1); Chip_GPIO_SetDir(LPC_GPIO_PORT,5,1<<2, 1); Chip_GPIO_SetDir(LPC_GPIO_PORT,5,1<<2, 1); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT,0,14); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT,1,11); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT,1,12); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT,5,0); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT,5,1); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT,5,2); }
void inicializacion_de_led (void) { Chip_GPIO_Init ( LPC_GPIO_PORT ); Chip_SCU_PinMux(2,0,MD_PUP,FUNC4); /* remapea P2_0 en GPIO5[0], LED0R y habilita el pull up*/ Chip_SCU_PinMux(2,1,MD_PUP,FUNC4); /* remapea P2_1 en GPIO5[1], LED0G y habilita el pull up */ Chip_SCU_PinMux(2,2,MD_PUP,FUNC4); /* remapea P2_2 en GPIO5[2], LED0B y habilita el pull up */ Chip_SCU_PinMux(2,10,MD_PUP,FUNC0); /* remapea P2_10 en GPIO0[14], LED1 y habilita el pull up */ Chip_SCU_PinMux(2,11,MD_PUP,FUNC0); /* remapea P2_11 en GPIO1[11], LED2 y habilita el pull up */ Chip_SCU_PinMux(2,12,MD_PUP,FUNC0); /* remapea P2_12 en GPIO1[12], LED3 y habilita el pull up */ Chip_GPIO_SetDir(LPC_GPIO_PORT, 5,(1<<0)|(1<<1)|(1<<2),1); /* aqui al puerto 5 le estoy dando a los bit 0, 1 y 2 (q son los led) los estoy inicializando como salida*/ Chip_GPIO_SetDir(LPC_GPIO_PORT, 0,(1<<14),1); Chip_GPIO_SetDir(LPC_GPIO_PORT, 1,(1<<11)|(1<<12),1); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 5, 0); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 5, 1); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 5, 2); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 0, 14); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 1, 11); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 1, 12); }
void led_off(void){ Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 5 , 1); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 5 , 2); }