void uartInit(int32u baudrate, int8u databits, SerialParity parity, int8u stopbits) { int32u tempcfg; assert( (baudrate >= 300) && (baudrate <=921600) ); SC1_UARTFRAC = 0; SC1_UARTPER = 104; // baudrate 115200 if(databits == 7) { tempcfg = 0; } else { tempcfg = SC_UART8BIT; } if (parity == PARITY_ODD) { tempcfg |= SC_UARTPAR | SC_UARTODD; } else if( parity == PARITY_EVEN ) { tempcfg |= SC_UARTPAR; } if ((stopbits & 0x0F) >= 2) { tempcfg |= SC_UART2STP; } SC1_UARTCFG = tempcfg; SC1_MODE = SC1_MODE_UART; /* rxHead=0; rxTail=0; rxUsed=0; */ // halGpioConfig(PORTB_PIN(1),GPIOCFG_OUT_ALT); // halGpioConfig(PORTB_PIN(2),GPIOCFG_IN); configureGPIO(PORTB_PIN(1), GPIOCFG_OUT_ALT); configureGPIO(PORTB_PIN(2), GPIOCFG_IN); // Make the RX Valid interrupt level sensitive (instead of edge) SC1_INTMODE = SC_RXVALLEVEL; // Enable just RX interrupts; TX interrupts are controlled separately INT_SC1CFG |= (INT_SCRXVAL | INT_SCRXOVF | INT_SC1FRMERR | INT_SC1PARERR); INT_SC1FLAG = 0xFFFF; // Clear any stale interrupts INT_CFGSET = INT_SC1; }
int serial_main() { int i, j = 0; SER_init(); configureGPIO(); while (1) { ledOn(); printf("Led On, Iteration %d\n\r", j); for (i = 0; i < 0x0007FFFF; i++) { } ledOff(); printf("Led Off, Iteration %d\n\r", j); for (i = 0; i < 0x0007FFFF; i++) { } j++; } }
int main(void) { //set up systick SysTick_Config(SystemCoreClock / 1000); configureSPI(); configureGPIO(); // uint16_t thispin = 0x00; // uint8_t up = 0x01; while(1) { // thispin = 0x0100; // while (thispin != 0x0000) { // if(up&0x01) // { // GPIO_SetBits(GPIOE, thispin); // thispin = thispin << 1; // } else { // GPIO_ResetBits(GPIOE, thispin); // thispin = thispin << 1; // } // delay(100); // } // // up ^= 0x01; GPIO_SetBits(GPIOA, GPIO_Pin_4); SPI_I2S_SendData16(SPI1, 0xA5); while(!SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE)); while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY)); GPIO_ResetBits(GPIOA, GPIO_Pin_4); GPIOE->ODR ^= 0xFF00; delay(100); } }
int main(void) { MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |SYSCTL_XTAL_12MHZ); //50MHZ // // Enable peripherals to operate when CPU is in sleep. // MAP_SysCtlPeripheralClockGating(true); // // Configure SysTick to occur 1000 times per second, to use as a time // reference. Enable SysTick to generate interrupts. // MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / SYSTICKS_PER_SECOND); MAP_SysTickIntEnable(); MAP_SysTickEnable(); // // Get the current processor clock frequency. // ulClockMS = MAP_SysCtlClockGet() / (3 * 1000); // init Serial Comm initSerialComm(230400); // init SSI0 in slave mode initSPIComm(); #ifdef DEBUG UARTprintf("Setting up PID\n"); #endif initCarPID(); #ifdef DEBUG UARTprintf("done\n"); #endif #ifdef DEBUG UARTprintf("Setting up PWM ... \n"); #endif configurePWM(); configureGPIO(); #ifdef DEBUG UARTprintf("done\n"); #endif #ifdef DEBUG UARTprintf("Setting up Servo ... \n"); #endif servo_init(); servo_setPosition(90); #ifdef DEBUG UARTprintf("done\n"); #endif #ifdef DEBUG UARTprintf("Starting QEI..."); #endif encoder_init(); #ifdef DEBUG UARTprintf("done\n"); #endif #ifdef USE_I2C #ifdef DEBUG UARTprintf("Setting up I2C\n"); #endif //I2C MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); MAP_GPIOPinTypeI2C(GPIO_PORTB_AHB_BASE,GPIO_PIN_2 | GPIO_PIN_3); MAP_I2CMasterInitExpClk(I2C0_MASTER_BASE,SysCtlClockGet(),true); //false = 100khz , true = 400khz I2CMasterTimeoutSet(I2C0_MASTER_BASE, 1000); #ifdef DEBUG UARTprintf("done\n"); #endif #endif #ifdef USE_I2C #ifdef USE_INA226 #ifdef DEBUG UARTprintf("Setting up INA226\n"); #endif initINA226(); #ifdef DEBUG UARTprintf("done\n"); #endif #endif #endif while (1) { } }