void mySPI_SendData(uint8_t adress, uint8_t data){ GPIO_PinWrite(GPIOE, 3,0); while(!SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE)); SPI_I2S_SendData(SPI1, adress); while(!SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE)); SPI_I2S_ReceiveData(SPI1); while(!SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE)); SPI_I2S_SendData(SPI1, data); while(!SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE)); SPI_I2S_ReceiveData(SPI1); GPIO_PinWrite(GPIOE, 3,1); }
int8_t mySPI_RecvData(uint8_t adress){ GPIO_PinWrite(GPIOE, 3,0); adress = adress | 0x80; while(!SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE)); SPI_I2S_SendData(SPI1, adress); while(!SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE)); SPI_I2S_ReceiveData(SPI1); while(!SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE)); SPI_I2S_SendData(SPI1, 0x00); while(!SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE)); GPIO_PinWrite(GPIOE, 3,1); return SPI_I2S_ReceiveData(SPI1); }
void Keyboard_Initialize (void) { uint32_t n; /* Configure pins: Input Mode (25 MHz) */ for (n = 0; n < NUM_KEYS; n++) { GPIO_PortClock (Pin_Key[n].port, true); GPIO_PinWrite (Pin_Key[n].port, Pin_Key[n].num, 0); GPIO_PinConfigure(Pin_Key[n].port, Pin_Key[n].num, GPIO_MODE_INPUT, GPIO_OUTPUT_PUSH_PULL, GPIO_OUTPUT_SPEED_25MHz, GPIO_NO_PULL_UP_DOWN); } RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI3_PC; /* button right */ SYSCFG->EXTICR[3] |= SYSCFG_EXTICR4_EXTI14_PB; /* button left */ NVIC_EnableIRQ(EXTI3_IRQn); NVIC_EnableIRQ(EXTI15_10_IRQn); /* Enable interrupts from both rising and falling edge of buttons */ EXTI->IMR |= EXTI_IMR_MR3 | EXTI_IMR_MR14; EXTI->RTSR |= EXTI_RTSR_TR3 | EXTI_RTSR_TR14; EXTI->FTSR |= EXTI_FTSR_TR3 | EXTI_FTSR_TR14; }
int main() { SystemInit(); SystemCoreClockUpdate(); GPIO_PinDirection(P2_0,OUTPUT); GPIO_PinDirection(P2_1,OUTPUT); GPIO_PinDirection(P2_2,OUTPUT); GPIO_PinDirection(P2_3,OUTPUT); GPIO_PinWrite(P2_0,1); UsbSerial_Init(9600); GPIO_PinWrite(P2_1,1); while(1) { UsbSerial_TxString(" Welcome to ARM Serial Programming by ExploreEmbedded\n\r"); } }
/*----------------------------------------------------------------------------- * LED_Initialize: Initialize LEDs * * Parameters: (none) * Return: (none) *----------------------------------------------------------------------------*/ void LED_Initialize (void) { uint32_t n; /* Configure pins: Push-pull Output Mode (50 MHz) with Pull-down resistors */ for (n = 0; n < NUM_LEDS; n++) { GPIO_PortClock (Pin_LED[n].port, true); GPIO_PinWrite (Pin_LED[n].port, Pin_LED[n].num, 0); GPIO_PinConfigure(Pin_LED[n].port, Pin_LED[n].num, GPIO_OUT_PUSH_PULL, GPIO_MODE_OUT2MHZ); } }
uint8_t I2C_Init(uint32_t MAP, uint32_t baudrate) { uint8_t i; map_t * pq = (map_t*)&(MAP); /* open drain and pull up */ for(i = 0; i < pq->pin_count; i++) { GPIO_Init(pq->io, pq->pin_start + i, kGPIO_Mode_OPP); GPIO_Init(pq->io, pq->pin_start + i, kGPIO_Mode_OPP); GPIO_PinWrite(pq->io, pq->pin_start + i, 1); SetPinPull(pq->io, pq->pin_start + i, 1); } /* i2c_gpio struct setup */ i2c.instace = pq->io; switch(MAP) { case I2C1_SCL_PE01_SDA_PE00: i2c.scl = 1;i2c.sda = 0; break; case I2C0_SCL_PE19_SDA_PE18: i2c.scl = 19;i2c.sda = 18; break; case I2C0_SCL_PF22_SDA_PF23: i2c.scl = 22;i2c.sda = 23; break; case I2C0_SCL_PB00_SDA_PB01: i2c.scl = 0;i2c.sda = 1; break; case I2C0_SCL_PB02_SDA_PB03: i2c.scl = 2;i2c.sda = 3; break; case I2C1_SCL_PC10_SDA_PC11: i2c.scl = 10;i2c.sda = 11; break; case I2C0_SCL_PD08_SDA_PD09: i2c.scl = 8;i2c.sda = 9; break; case I2C0_SCL_PE24_SDA_PE25: i2c.scl = 24;i2c.sda = 25; break; case I2C1_SCL_PC01_SDA_PC02: i2c.scl = 1;i2c.sda = 2; break; default: LIB_TRACE("no PINMAP found\r\n"); break; } return pq->ip; }
static int mcux_igpio_write(struct device *dev, int access_op, u32_t pin, u32_t value) { const struct mcux_igpio_config *config = dev->config->config_info; if (access_op == GPIO_ACCESS_BY_PIN) { GPIO_PinWrite(config->base, pin, value); } else { /* GPIO_ACCESS_BY_PORT */ config->base->DR = value; } return 0; }
/* start the main program */ void main() { uint8_t value; GPIO_PinDirection(SW1,INPUT); // Configure the switch pin as Input GPIO_PinDirection(Buzzer,OUTPUT); // Configure the Buzzer pin as OUTPUT while(1) { value = GPIO_PinRead(SW1); // Read the switch status GPIO_PinWrite(Buzzer,!value); // ON/OFF theBuzzer as per switch status } }
/** \fn int32_t LED_Initialize (void) \brief Initialize LEDs \returns - \b 0: function succeeded - \b -1: function failed */ int32_t LED_Initialize (void) { uint32_t n; /* Enable GPIO clock */ GPIO_PortClock (1); /* Configure pins: Output Mode with Pull-down resistors */ for (n = 0; n < LED_COUNT; n++) { SCU_PinConfigure (LED_PIN[n].port, LED_PIN[n].num, LED_PIN[n].config_val); GPIO_SetDir (LED_GPIO[n].port, LED_GPIO[n].num, GPIO_DIR_OUTPUT); GPIO_PinWrite (LED_GPIO[n].port, LED_GPIO[n].num, 0); } return 0; }
int main() { uint8_t value; SystemInit(); /* Clock and PLL configuration */ GPIO_PinFunction(MY_SWITCH,PINSEL_FUNC_0); /* Configure Pin for Gpio */ GPIO_PinDirection(MY_SWITCH,INPUT); /* Configure the switch pin as Input */ GPIO_PinFunction(MY_LED,PINSEL_FUNC_0); /* Configure Pin for Gpio */ GPIO_PinDirection(MY_LED,OUTPUT); /* Configure the Led pin as OUTPUT */ while(1) { value = GPIO_PinRead(MY_SWITCH); /* Read the switch status */ GPIO_PinWrite(MY_LED,value); /* ON/OFF the led as per switch status */ } }
/*----------------------------------------------------------------------------- * LED_Off: Turns off requested LED * * Parameters: num - LED number * Return: (none) *----------------------------------------------------------------------------*/ void LED_Off (uint32_t num) { GPIO_PinWrite(Pin_LED[num].port, Pin_LED[num].num, 0); }
/** \fn int32_t LED_Off (uint32_t num) \brief Turn off requested LED \param[in] num LED number \returns - \b 0: function succeeded - \b -1: function failed */ int32_t LED_Off (uint32_t num) { GPIO_PinWrite (LED_GPIO[num].port, LED_GPIO [num].num, 0); return 0; }