void Board_LEDs_Init(void) { Chip_GPIO_Init(LPC_GPIO); Chip_GPIO_WriteDirBit(LPC_GPIO, LED0, true); Chip_GPIO_WriteDirBit(LPC_GPIO, LED1, true); Chip_GPIO_WriteDirBit(LPC_GPIO, LED2, true); Chip_GPIO_WriteDirBit(LPC_GPIO, LED3, true); }
/** * [InitTask description] */ __task void InitTask(void) { int msg_len = 0; int clockRate = Chip_Clock_GetMainClockRate(); /* Enabled Clock To GPPIO */ Chip_GPIO_Init(LPC_GPIO); // Set the pin direction, set high for an output LED2 Chip_GPIO_SetPinDIR(LPC_GPIO, 0, 2, 1); /* Serial Driver Enable */ SER_Init(); msg_len = snprintf(message, sizeof(message), "Main clock is: %d\r\n", clockRate); Chip_UART0_SendRB(LPC_USART0, &txring, message, msg_len); for(;;) { os_dly_wait(50); Chip_UART0_SendRB(LPC_USART0, &txring, "Sveiki\r\n", strlen("Sveiki\r\n")); Chip_GPIO_WriteDirBit(LPC_GPIO, 0, 2, 0); os_dly_wait(100); Chip_GPIO_WriteDirBit(LPC_GPIO, 0, 2, 1); } }
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 InitGPIO(uint32_t num_motor) { //CONFIGURAR SALIDAS //----------------------------------------------------------------------------------------------- Chip_GPIO_WriteDirBit(LPC_GPIO, PORT_Qa_[num_motor][0], PIN_Qa_[num_motor][0] , SALIDA); //Configuro el pin como salida Chip_GPIO_WriteDirBit(LPC_GPIO, PORT_Qa_[num_motor][1], PIN_Qa_[num_motor][1] , SALIDA); //Configuro el pin como salida Chip_GPIO_WriteDirBit(LPC_GPIO, PORT_Qa_[num_motor][2], PIN_Qa_[num_motor][2] , SALIDA); //Configuro el pin como salida Chip_GPIO_WriteDirBit(LPC_GPIO, PORT_Qb_[num_motor][0], PIN_Qb_[num_motor][0] , SALIDA); //Configuro el pin como salida Chip_GPIO_WriteDirBit(LPC_GPIO, PORT_Qb_[num_motor][1], PIN_Qb_[num_motor][1] , SALIDA); //Configuro el pin como salida Chip_GPIO_WriteDirBit(LPC_GPIO, PORT_Qb_[num_motor][2], PIN_Qb_[num_motor][2] , SALIDA); //Configuro el pin como salida //APAGAR TRANSISTORES //----------------------------------------------------------------------------------------------- Chip_GPIO_WritePortBit(LPC_GPIO, PORT_Qa_[num_motor][0], PIN_Qa_[num_motor][0], 0); //PMOS Chip_GPIO_WritePortBit(LPC_GPIO, PORT_Qa_[num_motor][1], PIN_Qa_[num_motor][1], 0); //PMOS Chip_GPIO_WritePortBit(LPC_GPIO, PORT_Qa_[num_motor][2], PIN_Qa_[num_motor][2], 0); //PMOS Chip_GPIO_WritePortBit(LPC_GPIO, PORT_Qb_[num_motor][0], PIN_Qb_[num_motor][0], 1); //NMOS Chip_GPIO_WritePortBit(LPC_GPIO, PORT_Qb_[num_motor][1], PIN_Qb_[num_motor][1], 1); //NMOS Chip_GPIO_WritePortBit(LPC_GPIO, PORT_Qb_[num_motor][2], PIN_Qb_[num_motor][2], 1); //NMOS //CONFIGURAR ENTRADAS //----------------------------------------------------------------------------------------------- /*=============[TODAVIA NO ESTA IMPLEMENTADO]========================*/ Chip_GPIO_WriteDirBit(LPC_GPIO, PORT_Z_[num_motor][0], PIN_Z_[num_motor][0], ENTRADA); Chip_GPIO_WriteDirBit(LPC_GPIO, PORT_Z_[num_motor][1], PIN_Z_[num_motor][1], ENTRADA); Chip_GPIO_WriteDirBit(LPC_GPIO, PORT_Z_[num_motor][2], PIN_Z_[num_motor][2], ENTRADA); /*===================================================================*/ }
void Motor_Init(void) { Chip_GPIO_WriteDirBit(LPC_GPIO, MOTOR_STBY_PORT_NUM, MOTOR_STBY_BIT_NUM, true); int i; for(int i=0;i<NUM_MOTOR;i++) { Chip_GPIO_WriteDirBit(LPC_GPIO, MOTOR[i].pwm.port, MOTOR[i].pwm.bit, true); Chip_GPIO_WriteDirBit(LPC_GPIO, MOTOR[i].a.port, MOTOR[i].a.bit, true); Chip_GPIO_WriteDirBit(LPC_GPIO, MOTOR[i].b.port, MOTOR[i].b.bit, true); } Chip_GPIO_WritePortBit(LPC_GPIO, MOTOR_STBY_PORT_NUM, MOTOR_STBY_BIT_NUM, true); }
void Stepper_Init(STEPPER_MOTOR_T *mot){ //Initializes pins // Chip_GPIO_Init(LPC_GPIO); Chip_GPIO_WriteDirBit(LPC_GPIO, mot->ports[0], mot->pins[0], true); Chip_GPIO_WriteDirBit(LPC_GPIO, mot->ports[1], mot->pins[1], true); Chip_GPIO_WriteDirBit(LPC_GPIO, mot->ports[2], mot->pins[2], true); Chip_GPIO_WriteDirBit(LPC_GPIO, mot->ports[3], mot->pins[3], true); mot->zeroing = false; mot->pos = 0; mot->ticks = 0; mot->step_num = 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); }
/* Initialize the LEDs on the NXP LPC812 XPresso Board */ static void Board_LED_Init(void) { uint8_t i; for (i = 0; i < sizeof(LED_BITS); i++) { Chip_GPIO_WriteDirBit(LPC_GPIO_PORT, LPC8XX_PORT_NUM, LED_BITS[i], true); Chip_GPIO_WritePortBit(LPC_GPIO_PORT, LPC8XX_PORT_NUM, LED_BITS[i], (bool) true); } }
platform_result_t platform_gpio_init( const platform_gpio_t* gpio, platform_pin_config_t config ) { uint16_t mode; uint8_t direction; switch(config) { case INPUT_PULL_UP: { mode = IOCON_MODE_PULLUP; direction =LPC_PIN_INPUT; break; } case INPUT_PULL_DOWN: { mode = IOCON_MODE_PULLDOWN; direction =LPC_PIN_INPUT; break; } case INPUT_HIGH_IMPEDANCE: { mode = IOCON_MODE_INACT; direction =LPC_PIN_INPUT; break; } case OUTPUT_PUSH_PULL: { mode = IOCON_MODE_REPEATER; direction =LPC_PIN_OUTPUT; break; } case OUTPUT_OPEN_DRAIN_NO_PULL: { mode = IOCON_MODE_INACT; direction =LPC_PIN_OUTPUT; break; } case OUTPUT_OPEN_DRAIN_PULL_UP: { mode = IOCON_MODE_PULLUP; direction =LPC_PIN_OUTPUT; break; } default: { return PLATFORM_UNSUPPORTED; } } Chip_IOCON_PinMux(LPC_IOCON, gpio->port, gpio->pin, mode, IOCON_FUNC0); Chip_GPIO_WriteDirBit(LPC_GPIO, gpio->port, gpio->pin, direction ); return PLATFORM_SUCCESS; }
void Board_Joystick_Init(void) { Chip_IOCON_PinMux(LPC_IOCON, JOYSTICK_UP_GPIO_PORT_NUM, JOYSTICK_UP_GPIO_BIT_NUM, IOCON_MODE_INACT, IOCON_FUNC0); Chip_IOCON_PinMux(LPC_IOCON, JOYSTICK_DOWN_GPIO_PORT_NUM, JOYSTICK_DOWN_GPIO_BIT_NUM, IOCON_MODE_INACT, IOCON_FUNC0); Chip_IOCON_PinMux(LPC_IOCON, JOYSTICK_LEFT_GPIO_PORT_NUM, JOYSTICK_LEFT_GPIO_BIT_NUM, IOCON_MODE_INACT, IOCON_FUNC0); Chip_IOCON_PinMux(LPC_IOCON, JOYSTICK_RIGHT_GPIO_PORT_NUM, JOYSTICK_RIGHT_GPIO_BIT_NUM, IOCON_MODE_INACT, IOCON_FUNC0); Chip_IOCON_PinMux(LPC_IOCON, JOYSTICK_PRESS_GPIO_PORT_NUM, JOYSTICK_PRESS_GPIO_BIT_NUM, IOCON_MODE_INACT, IOCON_FUNC0); Chip_GPIO_WriteDirBit(LPC_GPIO, JOYSTICK_UP_GPIO_PORT_NUM, JOYSTICK_UP_GPIO_BIT_NUM, false); /* input */ Chip_GPIO_WriteDirBit(LPC_GPIO, JOYSTICK_DOWN_GPIO_PORT_NUM, JOYSTICK_DOWN_GPIO_BIT_NUM, false); /* input */ Chip_GPIO_WriteDirBit(LPC_GPIO, JOYSTICK_LEFT_GPIO_PORT_NUM, JOYSTICK_LEFT_GPIO_BIT_NUM, false); /* input */ Chip_GPIO_WriteDirBit(LPC_GPIO, JOYSTICK_RIGHT_GPIO_PORT_NUM, JOYSTICK_RIGHT_GPIO_BIT_NUM, false); /* input */ Chip_GPIO_WriteDirBit(LPC_GPIO, JOYSTICK_PRESS_GPIO_PORT_NUM, JOYSTICK_PRESS_GPIO_BIT_NUM, false); /* input */ }
/* Initialise the SCT Pins */ void SCT_PinsConfigure(void) { #ifdef BOARD_HITEX_EVA_18504350 /* Enable signals on MC connector X19 */ Chip_SCU_PinMuxSet(0xD, 9, (SCU_MODE_MODE_INACT | SCU_MODE_FUNC4)); /* PD_9: GPIO 6.23, MCSEL */ Chip_GPIO_WriteDirBit(LPC_GPIO_PORT, MCSEL_PORT, MCSEL_BIT, true); Chip_GPIO_WritePortBit(LPC_GPIO_PORT, MCSEL_PORT, MCSEL_BIT, false); /* Pin configuration for SCT */ /* PD_7: SCTIN_5 used for the CROSS_REQUEST input (button) */ Chip_SCU_PinMuxSet(0xD, 7, (SCU_MODE_MODE_REPEATER | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC1)); /* PD_10: SCTIN_1, used for SCT clock input */ /* Connect JP13 pin 1 with connector X19 pin2 */ Chip_SCU_PinMuxSet(0xD, 10, (SCU_MODE_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_FUNC1)); Chip_SCU_PinMuxSet(0xE, 6, (SCU_MODE_MODE_PULLUP | SCU_MODE_FUNC1)); /* PE_6: SCTOUT_2 connected to RGB green */ Chip_SCU_PinMuxSet(0xE, 5, (SCU_MODE_MODE_PULLUP | SCU_MODE_FUNC1)); /* PE_5: SCTOUT_3 connected to RGB red */ Chip_SCU_PinMuxSet(0xE, 8, (SCU_MODE_MODE_PULLUP | SCU_MODE_FUNC1)); /* P4_4: SCTOUT_4 connected to RGB blue */ Chip_SCU_PinMuxSet(0xE, 7, (SCU_MODE_MODE_PULLUP | SCU_MODE_FUNC1)); /* P4_3: SCTOUT_5 */ Chip_SCU_PinMuxSet(0xD, 3, (SCU_MODE_MODE_PULLUP | SCU_MODE_FUNC1)); /* PD_3: SCTOUT_6 */ /* Global configuration of the SCT */ /* use external clock, rising edge, on CTIN1 */ /* For Hitex4350, external clock is IRC clock /16 = 12 MHz / 16 = 750 KHz */ /* For Hitex1850, external clock is IRC clock /16 = 12 MHz / 16 = 750 KHz */ Chip_SCT_Config(LPC_SCT, (SCT_CONFIG_16BIT_COUNTER | (0x2 << 1) | (0x2 << 3))); #elif defined(BOARD_KEIL_MCB_18574357) /* PD_10: SCTIN_2, used for SCT clock input */ /* Connect PF_8 pin to CLK3 */ Chip_SCU_PinMuxSet(0xF, 8, (SCU_MODE_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_FUNC2)); Chip_SCU_PinMuxSet(0xD, 11, (SCU_MODE_MODE_PULLUP | SCU_MODE_FUNC6)); /* PD_11: SCTOUT_14 connected to LED1 */ Chip_SCU_PinMuxSet(0xD, 12, (SCU_MODE_MODE_PULLUP | SCU_MODE_FUNC6)); /* PD_12: SCTOUT_10 connected to LED2 */ Chip_SCU_PinMuxSet(0xD, 13, (SCU_MODE_MODE_PULLUP | SCU_MODE_FUNC6)); /* PD_13: SCTOUT_13 connected to LED3 */ Chip_SCU_PinMuxSet(0xD, 14, (SCU_MODE_MODE_PULLUP | SCU_MODE_FUNC6)); /* PD_14: SCTOUT_11 connected to LED4 */ Chip_SCU_PinMuxSet(0xD, 15, (SCU_MODE_MODE_PULLUP | SCU_MODE_FUNC6)); /* PD_15: SCTOUT_8 connected to LED5 */ /* Global configuration of the SCT */ /* use external clock, rising edge, on CTIN2 */ /* For Keil4357, external clock is IRC clock /16 = 12 MHz / 16 = 750 KHz */ /* For Keil1857, external clock is IRC clock /16 = 12 MHz / 16 = 750 KHz */ Chip_SCT_Config(LPC_SCT, (SCT_CONFIG_16BIT_COUNTER | (0x2 << 1) | (0x4 << 3))); #else #error Board not supported! #endif }
/* Initialize pin muxing for SPI interface */ void schBoard_SPI_Init(bool isMaster) { /* Set up clock and muxing for SSP0 interface */ /* * Initialize SSP0 pins connect * P0.15: SCK * P0.16: SSEL * P0.17: MISO * P0.18: MOSI */ Chip_IOCON_PinMux(LPC_IOCON, 0, 15, IOCON_MODE_PULLDOWN, IOCON_FUNC3); if (isMaster) { Chip_IOCON_PinMux(LPC_IOCON, 0, 16, IOCON_MODE_PULLUP, IOCON_FUNC0); Chip_GPIO_WriteDirBit(LPC_GPIO, 0, 16, true); Board_SPI_DeassertSSEL(); } else { Chip_IOCON_PinMux(LPC_IOCON, 0, 16, IOCON_MODE_PULLUP, IOCON_FUNC3); } Chip_IOCON_PinMux(LPC_IOCON, 0, 17, IOCON_MODE_INACT, IOCON_FUNC3); Chip_IOCON_PinMux(LPC_IOCON, 0, 18, IOCON_MODE_INACT, IOCON_FUNC3); }
int main(void) { uint32_t estado[4] ={0,0,0,0},suspender[4]={0,0,0,0}, StartMotores[4] = {0,0,0,0}; initHardware(); Chip_GPIO_WriteDirBit(LPC_GPIO, 2, 10, 1); //led isp Chip_GPIO_SetPinOutHigh(LPC_GPIO, 2,10); while(1) { if(available()) { read( &data_led[0], 4 ); data=data_led[0]; data=(data<<8)|data_led[1]; data=(data<<8)|data_led[2]; data=(data<<8)|data_led[3]; } if(data == 0xAABBCCDD) { Chip_GPIO_SetPinOutLow(LPC_GPIO, 2,10); //led isp StartMotores[2] = 1; StartMotores[3] = 1; } if(data == 0xEEFF0123) { Chip_GPIO_SetPinOutHigh(LPC_GPIO, 2,10); //led isp estado[2] = 0; estado[3] = 0; Stop_and_Default(0); //Condiciones iniciales Stop_and_Default(1); //Condiciones iniciales Stop_and_Default(2); //Condiciones iniciales Stop_and_Default(3); //Condiciones iniciales } if (StartMotores[2] && estado[2] == 0) { StartMotores[2] = 0; estado[2] = 1; msTick[2] = 0; } /* if (StartMotores[3] && estado[3] == 0) { StartMotores[3] = 0; estado[3] = 1; msTick[3] = 0; } */ if(estado[2] == 1) { if(msTick[2]) { msTick[2]=0; suspender[2]=Start_Up_Brushless(2); if(suspender[2]) { suspender[2] = 0; estado[2] = 2; } } } if(estado[2] == 2) { if(Conmutar[2]) { Conmutar[2] = 0; NextPWM(2); } } /* if(estado[3] == 1) { if(msTick[3]) { msTick[3]=0; suspender[3]=Start_Up_Brushless(3); if(suspender[3]) { suspender[3] = 0; estado[3] = 2; } } } if(estado[3] == 2) { if(Conmutar[3]) { Conmutar[3] = 0; NextPWM(3); } }*/ } return 0; }
/** * @brief main routine for ADC example * @return Function should not exit */ int main(void) { uint32_t rawSample; int j; SystemCoreClockUpdate(); Board_Init(); DEBUGSTR("ADC Demo\r\n"); /* Setup ADC for 12-bit mode and normal power */ Chip_ADC_Init(LPC_ADC, 0); /* Setup for maximum ADC clock rate */ Chip_ADC_SetClockRate(LPC_ADC, ADC_MAX_SAMPLE_RATE); /* Setup sequencer A for ADC channel 1, EOS interrupt */ #if defined(BOARD_MCORE48_1125) /* Setup a sequencer to do the following: Perform ADC conversion of ADC channel 1 only Trigger on low edge of PIO0_7 */ Chip_ADC_SetupSequencer(LPC_ADC, ADC_SEQA_IDX, (ADC_SEQ_CTRL_CHANSEL(1) | ADC_SEQ_CTRL_MODE_EOS | ADC_SEQ_CTRL_HWTRIG_PIO0_7)); /* Select ADC_1 mux for PIO1_11 */ Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO1_11, (IOCON_FUNC1 | IOCON_ADMODE_EN)); /* Setup GPIO PIO0_7 as an input (will kill LED out) */ Chip_GPIO_WriteDirBit(LPC_GPIO, 0, 7, false); /* Use higher voltage trim for MCore48 board */ Chip_ADC_SetTrim(LPC_ADC, ADC_TRIM_VRANGE_HIGHV); #endif /* Need to do a calibration after initialization and trim */ Chip_ADC_StartCalibration(LPC_ADC); while (!(Chip_ADC_IsCalibrationDone(LPC_ADC))) {} /* Setup threshold 0 low and high values to about 25% and 75% of max */ Chip_ADC_SetThrLowValue(LPC_ADC, 0, ((1 * 0xFFF) / 4)); Chip_ADC_SetThrHighValue(LPC_ADC, 0, ((3 * 0xFFF) / 4)); /* Clear all pending interrupts */ Chip_ADC_ClearFlags(LPC_ADC, Chip_ADC_GetFlags(LPC_ADC)); /* Enable ADC overrun and sequence A completion interrupts */ Chip_ADC_EnableInt(LPC_ADC, (ADC_INTEN_SEQA_ENABLE | ADC_INTEN_OVRRUN_ENABLE)); /* Use threshold 0 for channel 1 and enable threshold interrupt mode for channel as crossing */ Chip_ADC_SelectTH0Channels(LPC_ADC, ADC_THRSEL_CHAN_SEL_THR1(1)); Chip_ADC_SetThresholdInt(LPC_ADC, 1, ADC_INTEN_THCMP_CROSSING); /* Enable ADC NVIC interrupt */ NVIC_EnableIRQ(ADC_A_IRQn); /* Enable sequencer */ Chip_ADC_EnableSequencer(LPC_ADC, ADC_SEQA_IDX); /* Setup SyTick for a periodic rate */ SysTick_Config(SystemCoreClock / TICKRATE_HZ); /* Endless loop */ while (1) { /* Sleep until something happens */ __WFI(); if (thresholdCrossed) { thresholdCrossed = false; DEBUGSTR("********ADC threshold event********\r\n"); } /* Is a conversion sequence complete? */ if (sequenceComplete) { sequenceComplete = false; /* Get raw sample data for channels 1-8 */ for (j = 1; j <= 1; j++) { rawSample = Chip_ADC_GetDataReg(LPC_ADC, j); /* Show some ADC data */ DEBUGOUT("Sample value = 0x%x\r\n", ADC_DR_RESULT(rawSample)); DEBUGOUT("Threshold range = 0x%x\r\n", ADC_DR_THCMPRANGE(rawSample)); DEBUGOUT("Threshold cross = 0x%x\r\n", ADC_DR_THCMPCROSS(rawSample)); DEBUGOUT("Overrun = %d\r\n", ((rawSample & ADC_DR_OVERRUN) != 0)); DEBUGOUT("Data valid = %d\r\n", ((rawSample & ADC_SEQ_GDAT_DATAVALID) != 0)); DEBUGSTR("\r\n"); } } } /* Should not run to here */ return 0; }
/* Initializes board LED(s) */ static void Board_LED_Init(void) { /* Pin PIO0_22 is configured as GPIO pin during SystemInit */ /* Set the PIO_22 as output */ Chip_GPIO_WriteDirBit(LPC_GPIO, LED0_GPIO_PORT_NUM, LED0_GPIO_BIT_NUM, true); }
void Board_Buttons_Init(void) { Chip_GPIO_WriteDirBit(LPC_GPIO, BUTTONS_BUTTON1_GPIO_PORT_NUM, BUTTONS_BUTTON1_GPIO_BIT_NUM, false); }
/* Set the GPIO level of board LED */ void Board_LED_SetLevel(pinmux_t pinmux, bool high) { Chip_GPIO_WriteDirBit(LPC_GPIO_PORT, TO_PORT(pinmux), TO_PIN(pinmux), high); }