void stepper_set_stepping_rate(struct stepper *s, uint32_t stepping_rate){ s->stepping_rate = stepping_rate; TimerLoadSet(TIMER2_BASE, TIMER_A, SysCtlClockGet()/(s->stepping_rate * (256 / s->div))); }
//***************************************************************************** // // Configure the CAN and enter a loop to transmit periodic CAN messages. // //***************************************************************************** int main(void) { // // Set the clocking to run directly from the external crystal/oscillator. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal on your board. // SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Set up the serial console to use for displaying messages. This is // just for this example program and is not needed for CAN operation. // InitConsole(); // // For this example CAN0 is used with RX and TX pins on port D0 and D1. // The actual port and pins used may be different on your part, consult // the data sheet for more information. // GPIO port D needs to be enabled so these pins can be used. // TODO: change this to whichever GPIO port you are using // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // // Configure the GPIO pin muxing to select CAN0 functions for these pins. // This step selects which alternate function is available for these pins. // This is necessary if your part supports GPIO pin function muxing. // Consult the data sheet to see which functions are allocated per pin. // TODO: change this to select the port/pin you are using // GPIOPinConfigure(GPIO_PD0_CAN0RX); GPIOPinConfigure(GPIO_PD1_CAN0TX); // // Enable the alternate function on the GPIO pins. The above step selects // which alternate function is available. This step actually enables the // alternate function instead of GPIO for these pins. // TODO: change this to match the port/pin you are using // GPIOPinTypeCAN(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // The GPIO port and pins have been set up for CAN. The CAN peripheral // must be enabled. // SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0); // // Initialize the CAN controller // CANInit(CAN0_BASE); // // Set up the bit rate for the CAN bus. This function sets up the CAN // bus timing for a nominal configuration. You can achieve more control // over the CAN bus timing by using the function CANBitTimingSet() instead // of this one, if needed. // In this example, the CAN bus is set to 500 kHz. In the function below, // the call to SysCtlClockGet() is used to determine the clock rate that // is used for clocking the CAN peripheral. This can be replaced with a // fixed value if you know the value of the system clock, saving the extra // function call. For some parts, the CAN peripheral is clocked by a fixed // 8 MHz regardless of the system clock in which case the call to // SysCtlClockGet() should be replaced with 8000000. Consult the data // sheet for more information about CAN peripheral clocking. // CANBitRateSet(CAN0_BASE, SysCtlClockGet(), 500000); // // Enable interrupts on the CAN peripheral. This example uses static // allocation of interrupt handlers which means the name of the handler // is in the vector table of startup code. If you want to use dynamic // allocation of the vector table, then you must also call CANIntRegister() // here. // // CANIntRegister(CAN0_BASE, CANIntHandler); // if using dynamic vectors // CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS); // // Enable the CAN interrupt on the processor (NVIC). // IntEnable(INT_CAN0); // // Enable the CAN for operation. // CANEnable(CAN0_BASE); // // Initialize the message object that will be used for sending CAN // messages. The message will be 4 bytes that will contain an incrementing // value. Initially it will be set to 0. // // // Initialize message object 1 to be able to send CAN message 1. This // message object is not shared so it only needs to be initialized one // time, and can be used for repeatedly sending the same message ID. // g_sCANMsgObject1.ulMsgID = 0x1001; g_sCANMsgObject1.ulMsgIDMask = 0; g_sCANMsgObject1.ulFlags = MSG_OBJ_TX_INT_ENABLE; g_sCANMsgObject1.ulMsgLen = sizeof(g_ucMsg1); g_sCANMsgObject1.pucMsgData = g_ucMsg1; // // Initialize message object 2 to be able to send CAN message 2. This // message object is not shared so it only needs to be initialized one // time, and can be used for repeatedly sending the same message ID. // g_sCANMsgObject2.ulMsgID = 0x2001; g_sCANMsgObject2.ulMsgIDMask = 0; g_sCANMsgObject2.ulFlags = MSG_OBJ_TX_INT_ENABLE; g_sCANMsgObject2.ulMsgLen = sizeof(g_ucMsg2); g_sCANMsgObject2.pucMsgData = g_ucMsg2; // // Enter loop to send messages. Four messages will be sent once per // second. The contents of each message will be changed each time. // for(;;) { // // Send message 1 using CAN controller message object 1. This is // the only message sent using this message object. The // CANMessageSet() function will cause the message to be sent right // away. // PrintCANMessageInfo(&g_sCANMsgObject1, 1); CANMessageSet(CAN0_BASE, 1, &g_sCANMsgObject1, MSG_OBJ_TYPE_TX); // // Send message 2 using CAN controller message object 2. This is // the only message sent using this message object. The // CANMessageSet() function will cause the message to be sent right // away. // PrintCANMessageInfo(&g_sCANMsgObject2, 2); CANMessageSet(CAN0_BASE, 2, &g_sCANMsgObject2, MSG_OBJ_TYPE_TX); // // Load message object 3 with message 3. This is needs to be done each // time because message object 3 is being shared for two different // messages. // g_sCANMsgObject3.ulMsgID = 0x3001; g_sCANMsgObject3.ulMsgIDMask = 0; g_sCANMsgObject3.ulFlags = MSG_OBJ_TX_INT_ENABLE; g_sCANMsgObject3.ulMsgLen = sizeof(g_ucMsg3); g_sCANMsgObject3.pucMsgData = g_ucMsg3; // // Clear the flag that indicates that message 3 has been sent. This // flag will be set in the interrupt handler when a message has been // sent using message object 3. // g_bMsgObj3Sent = 0; // // Now send message 3 using CAN controller message object 3. This is // the first message sent using this message object. The // CANMessageSet() function will cause the message to be sent right // away. // PrintCANMessageInfo(&g_sCANMsgObject3, 3); CANMessageSet(CAN0_BASE, 3, &g_sCANMsgObject3, MSG_OBJ_TYPE_TX); // // Wait for the indication from the interrupt handler that message // object 3 is done, because we are re-using it for another message. // while(!g_bMsgObj3Sent) { } // // Load message object 3 with message 4. This is needed because // message object 3 is being shared for two different messages. // g_sCANMsgObject3.ulMsgID = 0x3002; g_sCANMsgObject3.ulMsgIDMask = 0; g_sCANMsgObject3.ulFlags = MSG_OBJ_TX_INT_ENABLE; g_sCANMsgObject3.ulMsgLen = sizeof(g_ucMsg4); g_sCANMsgObject3.pucMsgData = g_ucMsg4; // // Now send message 4 using CAN controller message object 3. This is // the second message sent using this message object. The // CANMessageSet() function will cause the message to be sent right // away. // PrintCANMessageInfo(&g_sCANMsgObject3, 3); CANMessageSet(CAN0_BASE, 3, &g_sCANMsgObject3, MSG_OBJ_TYPE_TX); // // Wait 1 second before continuing // SimpleDelay(); // // Check the error flag to see if errors occurred // if(g_bErrFlag) { UARTprintf(" error - cable connected?\n"); } else { // // If no errors then print the count of message sent // UARTprintf(" total count = %u\n", g_ulMsg1Count + g_ulMsg2Count + g_ulMsg3Count); } // // Change the value in the message data for each of the messages. // (*(unsigned long *)g_ucMsg1)++; (*(unsigned long *)g_ucMsg2)++; (*(unsigned long *)g_ucMsg3)++; (*(unsigned long *)&g_ucMsg4[0])++; (*(unsigned long *)&g_ucMsg4[4])--; } // // Return no errors // return(0); }
//***************************************************************************** // // Configure the CAN and enter a loop to receive CAN messages. // //***************************************************************************** int main(void) { #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) uint32_t ui32SysClock; #endif tCANMsgObject sCANMessage; uint8_t pui8MsgData[8]; // // Set the clocking to run directly from the external crystal/oscillator. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal used on your board. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_OSC) 25000000); #else SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); #endif // // Set up the serial console to use for displaying messages. This is // just for this example program and is not needed for CAN operation. // InitConsole(); // // For this example CAN0 is used with RX and TX pins on port B4 and B5. // The actual port and pins used may be different on your part, consult // the data sheet for more information. // GPIO port B needs to be enabled so these pins can be used. // TODO: change this to whichever GPIO port you are using // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // // Configure the GPIO pin muxing to select CAN0 functions for these pins. // This step selects which alternate function is available for these pins. // This is necessary if your part supports GPIO pin function muxing. // Consult the data sheet to see which functions are allocated per pin. // TODO: change this to select the port/pin you are using // GPIOPinConfigure(GPIO_PB4_CAN0RX); GPIOPinConfigure(GPIO_PB5_CAN0TX); // // Enable the alternate function on the GPIO pins. The above step selects // which alternate function is available. This step actually enables the // alternate function instead of GPIO for these pins. // TODO: change this to match the port/pin you are using // GPIOPinTypeCAN(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_5); // // The GPIO port and pins have been set up for CAN. The CAN peripheral // must be enabled. // SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0); // // Initialize the CAN controller // CANInit(CAN0_BASE); // // Set up the bit rate for the CAN bus. This function sets up the CAN // bus timing for a nominal configuration. You can achieve more control // over the CAN bus timing by using the function CANBitTimingSet() instead // of this one, if needed. // In this example, the CAN bus is set to 500 kHz. In the function below, // the call to SysCtlClockGet() or ui32SysClock is used to determine the // clock rate that is used for clocking the CAN peripheral. This can be // replaced with a fixed value if you know the value of the system clock, // saving the extra function call. For some parts, the CAN peripheral is // clocked by a fixed 8 MHz regardless of the system clock in which case // the call to SysCtlClockGet() or ui32SysClock should be replaced with // 8000000. Consult the data sheet for more information about CAN // peripheral clocking. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) CANBitRateSet(CAN0_BASE, ui32SysClock, 500000); #else CANBitRateSet(CAN0_BASE, SysCtlClockGet(), 500000); #endif // // Enable interrupts on the CAN peripheral. This example uses static // allocation of interrupt handlers which means the name of the handler // is in the vector table of startup code. If you want to use dynamic // allocation of the vector table, then you must also call CANIntRegister() // here. // // CANIntRegister(CAN0_BASE, CANIntHandler); // if using dynamic vectors // CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS); // // Enable the CAN interrupt on the processor (NVIC). // IntEnable(INT_CAN0); // // Enable the CAN for operation. // CANEnable(CAN0_BASE); // // Initialize a message object to receive CAN messages with ID 0x1001. // The expected ID must be set along with the mask to indicate that all // bits in the ID must match. // sCANMessage.ui32MsgID = 0x1001; sCANMessage.ui32MsgIDMask = 0xfffff; sCANMessage.ui32Flags = (MSG_OBJ_RX_INT_ENABLE | MSG_OBJ_USE_ID_FILTER | MSG_OBJ_EXTENDED_ID); sCANMessage.ui32MsgLen = 8; // // Now load the message object into the CAN peripheral message object 1. // Once loaded the CAN will receive any messages with this CAN ID into // this message object, and an interrupt will occur. // CANMessageSet(CAN0_BASE, 1, &sCANMessage, MSG_OBJ_TYPE_RX); // // Change the ID to 0x2001, and load into message object 2 which will be // used for receiving any CAN messages with this ID. Since only the CAN // ID field changes, we don't need to reload all the other fields. // sCANMessage.ui32MsgID = 0x2001; CANMessageSet(CAN0_BASE, 2, &sCANMessage, MSG_OBJ_TYPE_RX); // // Change the ID to 0x3001, and load into message object 3 which will be // used for receiving any CAN messages with this ID. Since only the CAN // ID field changes, we don't need to reload all the other fields. // sCANMessage.ui32MsgID = 0x3001; CANMessageSet(CAN0_BASE, 3, &sCANMessage, MSG_OBJ_TYPE_RX); // // Enter loop to process received messages. This loop just checks flags // for each of the 3 expected messages. The flags are set by the interrupt // handler, and if set this loop reads out the message and displays the // contents to the console. This is not a robust method for processing // incoming CAN data and can only handle one messages at a time per message // object. If many messages are being received close together using the // same message object, then some messages may be dropped. In a real // application, some other method should be used for queuing received // messages in a way to ensure they are not lost. You can also make use // of CAN FIFO mode which will allow messages to be buffered before they // are processed. // for(;;) { // // If the flag for message object 1 is set, that means that the RX // interrupt occurred and there is a message ready to be read from // this CAN message object. // if(g_bRXFlag1) { // // Reuse the same message object that was used earlier to configure // the CAN for receiving messages. A buffer for storing the // received data must also be provided, so set the buffer pointer // within the message object. This same buffer is used for all // messages in this example, but your application could set a // different buffer each time a message is read in order to store // different messages in different buffers. // sCANMessage.pui8MsgData = pui8MsgData; // // Read the message from the CAN. Message object number 1 is used // (which is not the same thing as CAN ID). The interrupt clearing // flag is not set because this interrupt was already cleared in // the interrupt handler. // CANMessageGet(CAN0_BASE, 1, &sCANMessage, 0); // // Clear the pending message flag so that the interrupt handler can // set it again when the next message arrives. // g_bRXFlag1 = 0; // // Print information about the message just received. // PrintCANMessageInfo(&sCANMessage, 1); } // // Check for message received on message object 2. If so then // read message and print information. // if(g_bRXFlag2) { sCANMessage.pui8MsgData = pui8MsgData; CANMessageGet(CAN0_BASE, 2, &sCANMessage, 0); g_bRXFlag2 = 0; PrintCANMessageInfo(&sCANMessage, 2); } // // Check for message received on message object 3. If so then // read message and print information. // if(g_bRXFlag3) { sCANMessage.pui8MsgData = pui8MsgData; CANMessageGet(CAN0_BASE, 3, &sCANMessage, 0); g_bRXFlag3 = 0; PrintCANMessageInfo(&sCANMessage, 3); } } // // Return no errors // return(0); }
//***************************************************************************** // // Configure SSI0 in master Freescale (SPI) mode. This example will send out // 3 bytes of data, then wait for 3 bytes of data to come in. This will all be // done using the polling method. // //***************************************************************************** int main(void) { unsigned long ulDataTx[NUM_SSI_DATA]; unsigned long ulDataRx[NUM_SSI_DATA]; unsigned long ulindex; // // Set the clocking to run directly from the external crystal/oscillator. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal on your board. // SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Set up the serial console to use for displaying messages. This is // just for this example program and is not needed for SSI operation. // InitConsole(); // // Display the setup on the console. // UARTprintf("SSI ->\n"); UARTprintf(" Mode: SPI\n"); UARTprintf(" Data: 8-bit\n\n"); // // The SSI0 peripheral must be enabled for use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); // // For this example SSI0 is used with PortA[5:2]. The actual port and pins // used may be different on your part, consult the data sheet for more // information. GPIO port A needs to be enabled so these pins can be used. // TODO: change this to whichever GPIO port you are using. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Configure the pin muxing for SSI0 functions on port A2, A3, A4, and A5. // This step is not necessary if your part does not support pin muxing. // TODO: change this to select the port/pin you are using. // GPIOPinConfigure(GPIO_PA2_SSI0CLK); GPIOPinConfigure(GPIO_PA3_SSI0FSS); GPIOPinConfigure(GPIO_PA4_SSI0RX); GPIOPinConfigure(GPIO_PA5_SSI0TX); // // Configure the GPIO settings for the SSI pins. This function also gives // control of these pins to the SSI hardware. Consult the data sheet to // see which functions are allocated per pin. // The pins are assigned as follows: // PA5 - SSI0Tx // PA4 - SSI0Rx // PA3 - SSI0Fss // PA2 - SSI0CLK // TODO: change this to select the port/pin you are using. // GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 | GPIO_PIN_2); // // Configure and enable the SSI port for SPI master mode. Use SSI0, // system clock supply, idle clock level low and active low clock in // freescale SPI mode, master mode, 1MHz SSI frequency, and 8-bit data. // For SPI mode, you can set the polarity of the SSI clock when the SSI // unit is idle. You can also configure what clock edge you want to // capture data on. Please reference the datasheet for more information on // the different SPI modes. // SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 1000000, 8); // // Enable the SSI0 module. // SSIEnable(SSI0_BASE); // // Read any residual data from the SSI port. This makes sure the receive // FIFOs are empty, so we don't read any unwanted junk. This is done here // because the SPI SSI mode is full-duplex, which allows you to send and // receive at the same time. The SSIDataGetNonBlocking function returns // "true" when data was returned, and "false" when no data was returned. // The "non-blocking" function checks if there is any data in the receive // FIFO and does not "hang" if there isn't. // while(SSIDataGetNonBlocking(SSI0_BASE, &ulDataRx[0])) { } // // Initialize the data to send. // ulDataTx[0] = 's'; ulDataTx[1] = 'p'; ulDataTx[2] = 'i'; // // Display indication that the SSI is transmitting data. // UARTprintf("Sent:\n "); // // Send 3 bytes of data. // for(ulindex = 0; ulindex < NUM_SSI_DATA; ulindex++) { // // Display the data that SSI is transferring. // UARTprintf("'%c' ", ulDataTx[ulindex]); // // Send the data using the "blocking" put function. This function // will wait until there is room in the send FIFO before returning. // This allows you to assure that all the data you send makes it into // the send FIFO. // SSIDataPut(SSI0_BASE, ulDataTx[ulindex]); } // // Wait until SSI0 is done transferring all the data in the transmit FIFO. // while(SSIBusy(SSI0_BASE)) { } // // Display indication that the SSI is receiving data. // UARTprintf("\nReceived:\n "); // // Receive 3 bytes of data. // for(ulindex = 0; ulindex < NUM_SSI_DATA; ulindex++) { // // Receive the data using the "blocking" Get function. This function // will wait until there is data in the receive FIFO before returning. // SSIDataGet(SSI0_BASE, &ulDataRx[ulindex]); // // Since we are using 8-bit data, mask off the MSB. // ulDataRx[ulindex] &= 0x00FF; // // Display the data that SSI0 received. // UARTprintf("'%c' ", ulDataRx[ulindex]); } // // Return no errors // return(0); }
void Systick_Init(void) { /* 1ms */ SysTick_Config((SysCtlClockGet()/1000)); }
//***************************************************************************** // //! Initializes and enables the specified I2C block. //! //! \param ulI2CBase is the I2C peripheral to be used. //! \param ulI2CSpeed defines the normal (100kbps) or fast (400kbps) I2C mode. //! //! This function enables the specified I2C block and sets it up to run at //! the either 100kbps or 400kbps. If the \e ulI2CSpeed is false, the I2C will //! run at 100kbps and if true, then the I2C will run at 400kbps. The //! \e ulI2CBase parameter can be one of the following values: //! //! - \b I2C0_MASTER_BASE //! - \b I2C1_MASTER_BASE //! - \b I2C2_MASTER_BASE //! - \b I2C3_MASTER_BASE //! //! \return None. // //***************************************************************************** void I2CSetup(unsigned long ulI2CBase, unsigned long ulI2CSpeed) { // // Check the arguments. // ASSERT(I2CMasterBaseValid(ulI2CBase)); ASSERT((ulI2CSpeed == true) || (ulI2CSpeed == false)); switch (ulI2CBase) { // I2C_PERIPH_0 case I2C0_MASTER_BASE: // // I2C0 is used with PortB[3:2]. The actual port and // pins used may be different on your part, consult the data sheet for // more information. GPIO port B needs to be enabled so these pins can // be used. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // // Select the I2C function for these pins. This function will also // configure the GPIO pins for I2C operation, setting them to // open-drain operation with weak pull-ups. Consult the data sheet // to see which functions are allocated per pin. // GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2); // special I2CSCL treatment for M4F devices GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3); // // Configure the pin muxing for I2C0 functions on port B2 and B3. // This step is not necessary if your part does not support pin muxing. // GPIOPinConfigure(GPIO_PB2_I2C0SCL); GPIOPinConfigure(GPIO_PB3_I2C0SDA); // // The I2C0 peripheral must be enabled before use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0); // // Enable and initialize the I2C0 master module. // I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), ulI2CSpeed); break; // I2C_PERIPH_1 case I2C1_MASTER_BASE: // // I2C1 is used with PortA[7:6]. The actual port and // pins used may be different on your part, consult the data sheet for // more information. GPIO port A needs to be enabled so these pins can // be used. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Select the I2C function for these pins. This function will also // configure the GPIO pins for I2C operation, setting them to // open-drain operation with weak pull-ups. Consult the data sheet // to see which functions are allocated per pin. // GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6); // special I2CSCL treatment for M4F devices GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7); // // Configure the pin muxing for I2C1 functions on port A6 and A7. // This step is not necessary if your part does not support pin muxing. // GPIOPinConfigure(GPIO_PA6_I2C1SCL); GPIOPinConfigure(GPIO_PA7_I2C1SDA); // // The I2C1 peripheral must be enabled before use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1); // // Enable and initialize the I2C1 master module. // I2CMasterInitExpClk(I2C1_MASTER_BASE, SysCtlClockGet(), ulI2CSpeed); break; // I2C_PERIPH_2 case I2C2_MASTER_BASE: // // I2C2 is used with PortE[5:4]. The actual port and // pins used may be different on your part, consult the data sheet for // more information. GPIO port E needs to be enabled so these pins can // be used. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // // Select the I2C function for these pins. This function will also // configure the GPIO pins for I2C operation, setting them to // open-drain operation with weak pull-ups. Consult the data sheet // to see which functions are allocated per pin. // GPIOPinTypeI2CSCL(GPIO_PORTE_BASE, GPIO_PIN_4); // special I2CSCL treatment for M4F devices GPIOPinTypeI2C(GPIO_PORTE_BASE, GPIO_PIN_5); // // Configure the pin muxing for I2C2 functions on port E4 and E5. // This step is not necessary if your part does not support pin muxing. // GPIOPinConfigure(GPIO_PE4_I2C2SCL); GPIOPinConfigure(GPIO_PE5_I2C2SDA); // // The I2C2 peripheral must be enabled before use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C2); // // Enable and initialize the I2C2 master module. // I2CMasterInitExpClk(I2C2_MASTER_BASE, SysCtlClockGet(), ulI2CSpeed); break; // I2C_PERIPH_3 case I2C3_MASTER_BASE: // // I2C3 is used with PortD[1:0]. The actual port and // pins used may be different on your part, consult the data sheet for // more information. GPIO port D needs to be enabled so these pins can // be used. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // // Select the I2C function for these pins. This function will also // configure the GPIO pins for I2C operation, setting them to // open-drain operation with weak pull-ups. Consult the data sheet // to see which functions are allocated per pin. // GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0); // special I2CSCL treatment for M4F devices GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1); // // Configure the pin muxing for I2C2 functions on port D0 and D1. // This step is not necessary if your part does not support pin muxing. // GPIOPinConfigure(GPIO_PD0_I2C3SCL); GPIOPinConfigure(GPIO_PD1_I2C3SDA); // // The I2C3 peripheral must be enabled before use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3); // // Enable and initialize the I2C3 master module. // I2CMasterInitExpClk(I2C3_MASTER_BASE, SysCtlClockGet(), ulI2CSpeed); break; } }
void readSensorData(GameState* state) { short dataX; short dataY; short dataZ; char printVal[10]; char chPwrCtlReg = 0x2D; char chX0Addr = 0x32; char chY0Addr = 0x34; char chZ0Addr = 0x36; char rgchReadAccl[] = { 0, 0, 0 }; char rgchWriteAccl[] = { 0, 0 }; char rgchReadAccl2[] = { 0, 0, 0 }; char rgchReadAccl3[] = { 0, 0, 0 }; int xDirThreshPos = 50; int xDirThreshNeg = -50; bool fDir = true; if(state->accelInitialized == 0){ /* * Enable I2C Peripheral */ SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0); SysCtlPeripheralReset(SYSCTL_PERIPH_I2C0); /* * Set I2C GPIO pins */ GPIOPinTypeI2C(I2CSDAPort, I2CSDA_PIN); GPIOPinTypeI2CSCL(I2CSCLPort, I2CSCL_PIN); GPIOPinConfigure(I2CSCL); GPIOPinConfigure(I2CSDA); /* * Setup I2C */ I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false); /* Initialize the Accelerometer * */ GPIOPinTypeGPIOInput(ACCL_INT2Port, ACCL_INT2); rgchWriteAccl[0] = chPwrCtlReg; rgchWriteAccl[1] = 1 << 3; // sets Accl in measurement mode I2CGenTransmit(rgchWriteAccl, 1, WRITE, ACCLADDR); state->accelInitialized = 1; } rgchReadAccl[0] = chX0Addr; rgchReadAccl2[0] = chY0Addr; rgchReadAccl3[0] = chZ0Addr; I2CGenTransmit(rgchReadAccl, 2, READ, ACCLADDR); I2CGenTransmit(rgchReadAccl2, 2, READ, ACCLADDR); I2CGenTransmit(rgchReadAccl3, 2, READ, ACCLADDR); dataX = (rgchReadAccl[2] << 8) | rgchReadAccl[1]; dataY = (rgchReadAccl2[2] << 8) | rgchReadAccl2[1]; dataZ = (rgchReadAccl3[2] << 8) | rgchReadAccl2[1]; state->accelY = dataY; }
//***************************************************************************** // // Configure the I2C0 master and slave and connect them using loopback mode. // //***************************************************************************** int main(void) { uint32_t ui32DataTx; // // Set the clocking to run directly from the external crystal/oscillator. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal on your board. // SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // The I2C0 peripheral must be enabled before use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0); // // For this example I2C0 is used with PortB[3:2]. The actual port and // pins used may be different on your part, consult the data sheet for // more information. GPIO port B needs to be enabled so these pins can // be used. // TODO: change this to whichever GPIO port you are using. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // // Configure the pin muxing for I2C0 functions on port B2 and B3. // This step is not necessary if your part does not support pin muxing. // TODO: change this to select the port/pin you are using. // GPIOPinConfigure(GPIO_PB2_I2C0SCL); GPIOPinConfigure(GPIO_PB3_I2C0SDA); // // Select the I2C function for these pins. This function will also // configure the GPIO pins pins for I2C operation, setting them to // open-drain operation with weak pull-ups. Consult the data sheet // to see which functions are allocated per pin. // TODO: change this to select the port/pin you are using. // GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2); GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3); // // Enable loopback mode. Loopback mode is a built in feature that helps // for debug the I2Cx module. It internally connects the I2C master and // slave terminals, which effectively lets you send data as a master and // receive data as a slave. NOTE: For external I2C operation you will need // to use external pull-ups that are faster than the internal pull-ups. // Refer to the datasheet for more information. // HWREG(I2C0_BASE + I2C_O_MCR) |= 0x01; // // Enable the I2C0 interrupt on the processor (NVIC). // IntEnable(INT_I2C0); // // Configure and turn on the I2C0 slave interrupt. The I2CSlaveIntEnableEx() // gives you the ability to only enable specific interrupts. For this case // we are only interrupting when the slave device receives data. // I2CSlaveIntEnableEx(I2C0_BASE, I2C_SLAVE_INT_DATA); // // Enable and initialize the I2C0 master module. Use the system clock for // the I2C0 module. The last parameter sets the I2C data transfer rate. // If false the data rate is set to 100kbps and if true the data rate will // be set to 400kbps. For this example we will use a data rate of 100kbps. // I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false); // // Enable the I2C0 slave module. // I2CSlaveEnable(I2C0_BASE); // // Set the slave address to SLAVE_ADDRESS. In loopback mode, it's an // arbitrary 7-bit number (set in a macro above) that is sent to the // I2CMasterSlaveAddrSet function. // I2CSlaveInit(I2C0_BASE, SLAVE_ADDRESS); // // Tell the master module what address it will place on the bus when // communicating with the slave. Set the address to SLAVE_ADDRESS // (as set in the slave module). The receive parameter is set to false // which indicates the I2C Master is initiating a writes to the slave. If // true, that would indicate that the I2C Master is initiating reads from // the slave. // I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS, false); // // Set up the serial console to use for displaying messages. This is just // for this example program and is not needed for proper I2C operation. // InitConsole(); // // Enable interrupts to the processor. // IntMasterEnable(); // // Display the example setup on the console. // UARTprintf("I2C Slave Interrupt Example ->"); UARTprintf("\n Module = I2C0"); UARTprintf("\n Mode = Receive interrupt on the Slave module"); UARTprintf("\n Rate = 100kbps\n\n"); // // Initialize the data to send. // ui32DataTx = 'I'; // // Indicate the direction of the data. // UARTprintf("Transferring from: Master -> Slave\n"); // // Display the data that I2C0 is transferring. // UARTprintf(" Sending: '%c'", ui32DataTx); // // Place the data to be sent in the data register. // I2CMasterDataPut(I2C0_BASE, ui32DataTx); // // Initiate send of single piece of data from the master. Since the // loopback mode is enabled, the Master and Slave units are connected // allowing us to receive the same data that we sent out. // I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND); // // Wait for interrupt to occur. // while(!g_bIntFlag) { } // // Display that interrupt was received. // UARTprintf("\n Slave Interrupt Received!\n"); // // Display the data that the slave has received. // UARTprintf(" Received: '%c'\n\n", g_ui32DataRx); // // Loop forever. // while(1) { } }
//***************************************************************************** // // Configure the I2C0 master and slave and connect them using loopback mode. // //***************************************************************************** int main(void) { unsigned long ulDataTx[NUM_I2C_DATA]; unsigned long ulDataRx[NUM_I2C_DATA]; unsigned long ulindex; // // Set the clocking to run directly from the external crystal/oscillator. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal on your board. // SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // The I2C0 peripheral must be enabled before use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0); // // For this example I2C0 is used with PortB[3:2]. The actual port and // pins used may be different on your part, consult the data sheet for // more information. GPIO port B needs to be enabled so these pins can // be used. // TODO: change this to whichever GPIO port you are using. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // // Configure the pin muxing for I2C0 functions on port B2 and B3. // This step is not necessary if your part does not support pin muxing. // TODO: change this to select the port/pin you are using. // GPIOPinConfigure(GPIO_PB2_I2C0SCL); GPIOPinConfigure(GPIO_PB3_I2C0SDA); // // Select the I2C function for these pins. This function will also // configure the GPIO pins pins for I2C operation, setting them to // open-drain operation with weak pull-ups. Consult the data sheet // to see which functions are allocated per pin. // TODO: change this to select the port/pin you are using. // GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3); // // Enable loopback mode. Loopback mode is a built in feature that is // useful for debugging I2C operations. It internally connects the I2C // master and slave terminals, which effectively let's you send data as // a master and receive data as a slave. // NOTE: For external I2C operation you will need to use external pullups // that are stronger than the internal pullups. Refer to the datasheet for // more information. // HWREG(I2C0_MASTER_BASE + I2C_O_MCR) |= 0x01; // // Enable and initialize the I2C0 master module. Use the system clock for // the I2C0 module. The last parameter sets the I2C data transfer rate. // If false the data rate is set to 100kbps and if true the data rate will // be set to 400kbps. For this example we will use a data rate of 100kbps. // I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), false); // // Enable the I2C0 slave module. This module is enabled only for testing // purposes. It does not need to be enabled for proper operation of the // I2Cx master module. // I2CSlaveEnable(I2C0_SLAVE_BASE); // // Set the slave address to SLAVE_ADDRESS. In loopback mode, it's an // arbitrary 7-bit number (set in a macro above) that is sent to the // I2CMasterSlaveAddrSet function. // I2CSlaveInit(I2C0_SLAVE_BASE, SLAVE_ADDRESS); // // Tell the master module what address it will place on the bus when // communicating with the slave. Set the address to SLAVE_ADDRESS // (as set in the slave module). The receive parameter is set to false // which indicates the I2C Master is initiating a writes to the slave. If // true, that would indicate that the I2C Master is initiating reads from // the slave. // I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, false); // // Set up the serial console to use for displaying messages. This is // just for this example program and is not needed for I2C operation. // InitConsole(); // // Display the example setup on the console. // UARTprintf("I2C Loopback Example ->"); UARTprintf("\n Module = I2C0"); UARTprintf("\n Mode = Single Send/Receive"); UARTprintf("\n Rate = 100kbps\n\n"); // // Initalize the data to send. // ulDataTx[0] = 'I'; ulDataTx[1] = '2'; ulDataTx[2] = 'C'; // // Initalize the receive buffer. // for(ulindex = 0; ulindex < NUM_I2C_DATA; ulindex++) { ulDataRx[ulindex] = 0; } // // Indicate the direction of the data. // UARTprintf("Tranferring from: Master -> Slave\n"); // // Send 3 peices of I2C data from the master to the slave. // for(ulindex = 0; ulindex < NUM_I2C_DATA; ulindex++) { // // Display the data that the I2C0 master is transferring. // UARTprintf(" Sending: '%c' . . . ", ulDataTx[ulindex]); // // Place the data to be sent in the data register // I2CMasterDataPut(I2C0_MASTER_BASE, ulDataTx[ulindex]); // // Initiate send of data from the master. Since the loopback // mode is enabled, the master and slave units are connected // allowing us to receive the same data that we sent out. // I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND); // // Wait until the slave has received and acknowledged the data. // while(!(I2CSlaveStatus(I2C0_SLAVE_BASE) & I2C_SCSR_RREQ)) { } // // Read the data from the slave. // ulDataRx[ulindex] = I2CSlaveDataGet(I2C0_SLAVE_BASE); // // Wait until master module is done transferring. // while(I2CMasterBusy(I2C0_MASTER_BASE)) { } // // Display the data that the slave has received. // UARTprintf("Received: '%c'\n", ulDataRx[ulindex]); } // // Reset receive buffer. // for(ulindex = 0; ulindex < NUM_I2C_DATA; ulindex++) { ulDataRx[ulindex] = 0; } // // Indicate the direction of the data. // UARTprintf("\n\nTranferring from: Slave -> Master\n"); // // Modifiy the data direction to true, so that seeing the address will // indicate that the I2C Master is initiating a read from the slave. // I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, true); // // Do a dummy receive to make sure you don't get junk on the first receive. // I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE); // // Dummy acknowledge and wait for the receive request from the master. // This is done to clear any flags that should not be set. // while(!(I2CSlaveStatus(I2C0_SLAVE_BASE) & I2C_SLAVE_ACT_TREQ)) { } for(ulindex = 0; ulindex < NUM_I2C_DATA; ulindex++) { // // Display the data that I2C0 slave module is transferring. // UARTprintf(" Sending: '%c' . . . ", ulDataTx[ulindex]); // // Place the data to be sent in the data register // I2CSlaveDataPut(I2C0_SLAVE_BASE, ulDataTx[ulindex]); // // Tell the master to read data. // I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE); // // Wait until the slave is done sending data. // while(!(I2CSlaveStatus(I2C0_SLAVE_BASE) & I2C_SLAVE_ACT_TREQ)) { } // // Read the data from the master. // ulDataRx[ulindex] = I2CMasterDataGet(I2C0_MASTER_BASE); // // Display the data that the slave has received. // UARTprintf("Received: '%c'\n", ulDataRx[ulindex]); } // // Tell the user that the test is done. // UARTprintf("\nDone.\n\n"); // // Return no errors // return(0); }
//***************************************************************************** // // A simple demonstration of the features of the Stellaris Graphics Library. // //***************************************************************************** int main(void) { tContext sContext; tRectangle sRect; // // If running on Rev A2 silicon, turn the LDO voltage up to 2.75V. This is // a workaround to allow the PLL to operate reliably. // if(REVISION_IS_A2) { SysCtlLDOSet(SYSCTL_LDO_2_75V); } // // Set the clocking to run from the PLL. // SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Turn on the backlight. // Kitronix320x240x16_SSD2119BacklightOn(255); // // Set graphics library text rendering defaults. // GrLibInit(&GRLIB_INIT_STRUCT); // // Set the string table and the default language. // GrStringTableSet(STRING_TABLE); // // Set the default language. // ChangeLanguage(GrLangEnUS); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKitronix320x240x16_SSD2119); // // Fill the top 26 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1; sRect.sYMax = 25; GrContextForegroundSet(&sContext, ClrDarkBlue); GrRectFill(&sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&sContext, ClrWhite); GrRectDraw(&sContext, &sRect); // // Load the static strings from the string table. These strings are // independent of the language in use but we store them in the string // table nonetheless since (a) we may be using codepage remapping in // which case it would be difficult to hardcode them into the app source // anyway (ASCII or ISO8859-1 text would not render properly with the // remapped custom font) and (b) even if we're not using codepage remapping, // we may have generated a custom font from the string table output and // we want to make sure that all glyphs required by the application are // present in that font. If we hardcode some text in the application // source and don't put it in the string table, we run the risk of having // characters missing in the font. // GrStringGet(STR_ENGLISH, g_pcEnglish, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_DEUTSCH, g_pcDeutsch, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_ESPANOL, g_pcEspanol, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_ITALIANO, g_pcItaliano, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_CHINESE, g_pcChinese, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_KOREAN, g_pcKorean, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_JAPANESE, g_pcJapanese, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_PLUS, g_pcPlus, 2); GrStringGet(STR_MINUS, g_pcMinus, 2); // // Put the application name in the middle of the banner. // GrStringGet(STR_APPNAME, g_pcBuffer, SCOMP_MAX_STRLEN); GrContextFontSet(&sContext, FONT_20PT); GrStringDrawCentered(&sContext, g_pcBuffer, -1, GrContextDpyWidthGet(&sContext) / 2, 10, 0); // // Initialize the sound driver. // SoundInit(); // // Initialize the touch screen driver and have it route its messages to the // widget tree. // TouchScreenInit(); TouchScreenCallbackSet(WidgetPointerMessage); // // Add the title block and the previous and next buttons to the widget // tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sPrevious); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sTitle); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sNext); // // Add the first panel to the widget tree. // g_ulPanel = 0; WidgetAdd(WIDGET_ROOT, (tWidget *)g_psPanels); // // Set the string for the title. // CanvasTextSet(&g_sTitle, g_pcTitle); // // Initialize the pointer to the button text. // PushButtonTextSet(&g_sFirmwareUpdateBtn, g_pcUpdateButton); // // Issue the initial paint request to the widgets. // WidgetPaint(WIDGET_ROOT); // // Loop forever unless we receive a signal that a firmware update has been // requested. // while(!g_bFirmwareUpdate) { // // Process any messages in the widget message queue. // WidgetMessageQueueProcess(); } // // If we drop out, a firmware update request has been made. We call // WidgetMessageQueueProcess once more to ensure that any final messages // are processed then jump into the bootloader. // WidgetMessageQueueProcess(); // // Wait a while for the last keyboard click sound to finish. This is about // 500mS since the delay loop is 3 cycles long. // SysCtlDelay(SysCtlClockGet() / 6); // // Pass control to the bootloader. // JumpToBootLoader(); // // The boot loader should take control, so this should never be reached. // Just in case, loop forever. // while(1) { } }
/* * portno从0开始编号 */ sys_cfg_err_t sys_cfg_uart(struct uart_param *cfgdata, int portno) { unsigned long base; unsigned long cfg; /* portno, cfgdata->databits, cfgdata->stopbits, cfgdata->paritybit */ if (portno>=UART_PORT_NUM || NULL==cfgdata) { return SYS_CFG_PARAM_ERR; } /* 对波特率进行检查的代码还未编写!!! */ if (cfgdata->databits < UART_DATA_BITS_MIN || cfgdata->databits > UART_DATA_BITS_MAX || cfgdata->stopbits < UART_STOP_BITS_MIN || cfgdata->stopbits > UART_STOP_BITS_MIN) { return SYS_CFG_DATA_ERR; } switch (portno) { case 0: base = UART0_BASE; break; case 1: base = UART1_BASE; break; case 2: /* UART_PORT_NUM - 1 */ base = UART2_BASE; break; default: /* 这种情况不应该出现, 现在只是做简单的处理 */ return SYS_CFG_PARAM_ERR; } cfg = 0; switch (cfgdata->databits) { case 5: /* UART_DATA_BITS_MIN */ cfg |= UART_CONFIG_WLEN_5; break; case 6: cfg |= UART_CONFIG_WLEN_6; break; case 7: cfg |= UART_CONFIG_WLEN_7; break; case 8: /* UART_DATA_BITS_MAX */ cfg |= UART_CONFIG_WLEN_8; break; default: /* 这种情况不应该出现, 现在只是做简单的处理 */ return SYS_CFG_PARAM_ERR; } if (1 == cfgdata->stopbits) cfg |= UART_CONFIG_STOP_ONE; else if (2 == cfgdata->stopbits) cfg |= UART_CONFIG_STOP_TWO; else return SYS_CFG_PARAM_ERR; switch (cfgdata->paritybit) { case UART_PAR_NONE: cfg |= UART_CONFIG_PAR_NONE; break; case UART_PAR_EVEN: cfg |= UART_CONFIG_PAR_EVEN; break; case UART_PAR_ODD: cfg |= UART_CONFIG_PAR_ODD; break; case UART_PAR_ONE: cfg |= UART_CONFIG_PAR_ONE; break; case UART_PAR_ZERO: cfg |= UART_CONFIG_PAR_ZERO; break; default: return SYS_CFG_PARAM_ERR; } // Configure the UART for 115,200, 8-N-1 operation. // This function uses SysCtlClockGet() to get the system clock // frequency. This could be also be a variable or hard coded value // instead of a function call. UARTConfigSetExpClk(base, SysCtlClockGet(), cfgdata->baudrate, cfg); return SYS_CFG_SUCC; }
//***************************************************************************** // //! Initializes the touch screen driver. //! //! This function initializes the touch screen driver, beginning the process of //! reading from the touch screen. This driver uses the following hardware //! resources: //! //! - ADC sample sequence 3 //! - Timer 0 subtimer A //! //! \return None. // //***************************************************************************** void TouchScreenInit(void) { unsigned short usController; // // Set the initial state of the touch screen driver's state machine. // g_ulTSState = TS_STATE_INIT; // // There is no touch screen handler initially. // g_pfnTSHandler = 0; // // Determine which display controller is in use and, from this, determine // what the sense of the Y axis must be. The -F03 version of the display // containing an ILI9320 controller reverses the sense of the Y axis // relative to the later -F05 and -F02 versions containing ILI9325 and // ILI9328 controllers respectively. // usController = Formike240x320x16_ILI9320ControllerIdGet(); g_bReverseLongAxis = ((usController != 0x9320) ? true : false); // // Enable the peripherals used by the touch screen interface. // SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // // Configure the ADC sample sequence used to read the touch screen reading. // ADCHardwareOversampleConfigure(ADC0_BASE, 4); ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0); ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH6 | ADC_CTL_END | ADC_CTL_IE); ADCSequenceEnable(ADC0_BASE, 3); // // Enable the ADC sample sequence interrupt. // ADCIntEnable(ADC0_BASE, 3); IntEnable(INT_ADC0SS3); // // Configure the GPIOs used to drive the touch screen layers. // GPIOPinTypeGPIOOutput(TS_X_BASE, TS_XP_PIN | TS_XN_PIN); GPIOPinTypeGPIOOutput(TS_Y_BASE, TS_YP_PIN | TS_YN_PIN); GPIOPinWrite(TS_X_BASE, TS_XP_PIN | TS_XN_PIN, 0x00); GPIOPinWrite(TS_Y_BASE, TS_YP_PIN | TS_YN_PIN, 0x00); // // See if the ADC trigger timer has been configured, and configure it only // if it has not been configured yet. // if((HWREG(TIMER0_BASE + TIMER_O_CTL) & TIMER_CTL_TAEN) == 0) { // // Configure the timer to trigger the sampling of the touch screen // every millisecond. // TimerConfigure(TIMER0_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC)); TimerLoadSet(TIMER0_BASE, TIMER_A, (SysCtlClockGet() / 1000) - 1); TimerControlTrigger(TIMER0_BASE, TIMER_A, true); // // Enable the timer. At this point, the touch screen state machine // will sample and run once per millisecond. // TimerEnable(TIMER0_BASE, TIMER_A); } }
//***************************************************************************** // // This example demonstrates how to send a string of data to the UART. // //***************************************************************************** int main(void) { // // Set the clocking to run directly from the crystal. // SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Initialize the OLED display and write status. // RIT128x96x4Init(1000000); RIT128x96x4StringDraw("UART Echo", 36, 0, 15); RIT128x96x4StringDraw("Port: Uart 0", 12, 16, 15); RIT128x96x4StringDraw("Baud: 115,200 bps", 12, 24, 15); RIT128x96x4StringDraw("Data: 8 Bit", 12, 32, 15); RIT128x96x4StringDraw("Parity: None", 12, 40, 15); RIT128x96x4StringDraw("Stop: 1 Bit", 12, 48, 15); // // Enable the peripherals used by this example. // SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Enable processor interrupts. // IntMasterEnable(); // // Set GPIO A0 and A1 as UART pins. // GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Configure the UART for 115,200, 8-N-1 operation. // UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // // Enable the UART interrupt. // IntEnable(INT_UART0); UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); // // Prompt for text to be entered. // UARTSend((unsigned char *)"Enter text: ", 12); // // Loop forever echoing data through the UART. // while(1) { } }
//***************************************************************************** // // Main function performs init and manages system. // // Called automatically after the system and compiler pre-init sequences. // Performs system init calls, restores state from hibernate if needed and // then manages the application context duties of the system. // //***************************************************************************** int main(void) { uint32_t ui32Status; uint32_t ui32ResetCause; int32_t i32CommandStatus; // // Enable stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPUEnable(); ROM_FPUStackingEnable(); // // Set the system clock to run at 40Mhz off PLL with external crystal as // reference. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // // Enable the hibernate module // SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE); // // Enable and Initialize the UART. // ConfigureUART(); UARTprintf("Welcome to the Tiva C Series TM4C123G LaunchPad!\n"); UARTprintf("Type 'help' for a list of commands\n"); UARTprintf("> "); // // Determine why system reset occurred and respond accordingly. // ui32ResetCause = SysCtlResetCauseGet(); SysCtlResetCauseClear(ui32ResetCause); if(ui32ResetCause == SYSCTL_CAUSE_POR) { if(HibernateIsActive()) { // // Read the status bits to see what caused the wake. // ui32Status = HibernateIntStatus(0); HibernateIntClear(ui32Status); // // Wake was due to the push button. // if(ui32Status & HIBERNATE_INT_PIN_WAKE) { UARTprintf("Hibernate Wake Pin Wake Event\n"); UARTprintf("> "); // // Recover the application state variables from battery backed // hibernate memory. Set ui32Mode to normal. // HibernateDataGet((uint32_t*) &g_sAppState, sizeof(tAppState) / 4 + 1); g_sAppState.ui32Mode = APP_MODE_NORMAL; } // // Wake was due to RTC match // else if(ui32Status & HIBERNATE_INT_RTC_MATCH_0) { UARTprintf("Hibernate RTC Wake Event\n"); UARTprintf("> "); // // Recover the application state variables from battery backed // hibernate memory. Set ui32Mode to briefly flash the RGB. // HibernateDataGet((uint32_t*) &g_sAppState, sizeof(tAppState) / 4 + 1); g_sAppState.ui32Mode = APP_MODE_HIB_FLASH; } } else { // // Reset was do to a cold first time power up. // UARTprintf("Power on reset. Hibernate not active.\n"); UARTprintf("> "); g_sAppState.ui32Mode = APP_MODE_NORMAL; g_sAppState.fColorWheelPos = 0; g_sAppState.fIntensity = APP_INTENSITY_DEFAULT; g_sAppState.ui32Buttons = 0; } } else { // // External Pin reset or other reset event occured. // UARTprintf("External or other reset\n"); UARTprintf("> "); // // Treat this as a cold power up reset without restore from hibernate. // g_sAppState.ui32Mode = APP_MODE_NORMAL; g_sAppState.fColorWheelPos = APP_PI; g_sAppState.fIntensity = APP_INTENSITY_DEFAULT; g_sAppState.ui32Buttons = 0; // // colors get a default initialization later when we call AppRainbow. // } // // Initialize clocking for the Hibernate module // HibernateEnableExpClk(SysCtlClockGet()); // // Initialize the RGB LED. AppRainbow typically only called from interrupt // context. Safe to call here to force initial color update because // interrupts are not yet enabled. // RGBInit(0); RGBIntensitySet(g_sAppState.fIntensity); AppRainbow(1); RGBEnable(); // // Initialize the buttons // ButtonsInit(); // // Initialize the SysTick interrupt to process colors and buttons. // SysTickPeriodSet(SysCtlClockGet() / APP_SYSTICKS_PER_SEC); SysTickEnable(); SysTickIntEnable(); IntMasterEnable(); // // spin forever and wait for carriage returns or state changes. // while(1) { UARTprintf("\n>"); // // Peek to see if a full command is ready for processing // while(UARTPeek('\r') == -1) { // // millisecond delay. A SysCtlSleep() here would also be OK. // SysCtlDelay(SysCtlClockGet() / (1000 / 3)); // // Check for change of mode and enter hibernate if requested. // all other mode changes handled in interrupt context. // if(g_sAppState.ui32Mode == APP_MODE_HIB) { AppHibernateEnter(); } } // // a '\r' was detected get the line of text from the user. // UARTgets(g_cInput,sizeof(g_cInput)); // // Pass the line from the user to the command processor. // It will be parsed and valid commands executed. // i32CommandStatus = CmdLineProcess(g_cInput); // // Handle the case of bad command. // if(i32CommandStatus == CMDLINE_BAD_CMD) { UARTprintf("Bad command!\n"); } // // Handle the case of too many arguments. // else if(i32CommandStatus == CMDLINE_TOO_MANY_ARGS) { UARTprintf("Too many arguments for command processor!\n"); } } }
void Startup(void) { //STEP 1: OLED and PWM setup unsigned long ulPeriod; SysCtlPWMClockSet(SYSCTL_PWMDIV_1); SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); GPIOPinTypePWM(GPIO_PORTG_BASE, GPIO_PIN_1); ulPeriod = SysCtlClockGet() / 4000; PWMGenConfigure(PWM0_BASE, PWM_GEN_0,PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ulPeriod); PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, ulPeriod / 16); PWMGenEnable(PWM0_BASE, PWM_GEN_0); //STEP 3: Button pad setup TrainState = 0; GPIOPortIntUnregister(GPIO_PORTE_BASE); GPIOPortIntRegister(GPIO_PORTE_BASE,IntGPIOe); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, 0xF); GPIOPadConfigSet(GPIO_PORTE_BASE, 0xF , GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); GPIOIntTypeSet(GPIO_PORTE_BASE, 0xF , GPIO_FALLING_EDGE); GPIOPinIntEnable(GPIO_PORTE_BASE, 0xF ); IntEnable(INT_GPIOE); IntPrioritySet( INT_UART0, configKERNEL_INTERRUPT_PRIORITY); //STEP 4: Frequency count setup tempCount = 0; frequencyCount = 0; SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_3); GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); GPIOPortIntUnregister(GPIO_PORTF_BASE); GPIOPortIntRegister(GPIO_PORTF_BASE,IntGPIOf); GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_RISING_EDGE); GPIOPinIntEnable(GPIO_PORTF_BASE, GPIO_PIN_3); IntEnable(INT_GPIOF); //IntPrioritySet( INT_GPIOF, 10); //STEP 5: UART setup SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); IntEnable(INT_UART0); UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); // IntPrioritySet( INT_UART0, configKERNEL_INTERRUPT_PRIORITY); //STEP 6: pin setup /*SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, PORT_DATA);*/ //STEP 7: ADC SETUP SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); ADCSequenceDisable(ADC0_BASE,0); ADCSequenceDisable(ADC0_BASE,1); ADCSequenceDisable(ADC0_BASE,2); ADCSequenceDisable(ADC0_BASE,3); GPIOPinTypeADC(ADC0_BASE, 0xF); ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 0); ADCSequenceEnable(ADC0_BASE, 1); ADCSequenceEnable(ADC0_BASE, 2); ADCSequenceEnable(ADC0_BASE, 3); ADCIntClear(ADC0_BASE, 0); ADCIntClear(ADC0_BASE, 1); ADCIntClear(ADC0_BASE, 2); ADCIntClear(ADC0_BASE, 3); ADCIntEnable(ADC0_BASE, 0); ADCIntEnable(ADC0_BASE, 1); ADCIntEnable(ADC0_BASE, 2); ADCIntEnable(ADC0_BASE, 3); //IntEnable(INT_ADC0); //IntPrioritySet(INT_ADC, 50); //IntEnable(INT_ADC0); //ADCIntClear(ADC0_BASE, 0); return; }
//***************************************************************************** // // Initialize the IO used in this demo // 1. STATUS LED on Port F pin 0 // 2. PWM on Port D Pin 1 (PWM1) // //***************************************************************************** void io_init(void) { unsigned long ulPWMClock; // // Enable GPIO bank F to allow control of the LED. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Configure Port F0 for as an output for the status LED. // GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_0); // // Initialize LED to OFF (0) // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0); // // Enable Port G1 for PWM output. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); GPIOPinTypePWM(GPIO_PORTG_BASE,GPIO_PIN_1); // // Enable the PWM generator. // SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM); // // Configure the PWM generator for count down mode with immediate updates // to the parameters. // PWMGenConfigure(PWM_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC); // // Divide the PWM clock by 4. // SysCtlPWMClockSet(SYSCTL_PWMDIV_4); // // Get the PWM clock. // ulPWMClock = SysCtlClockGet()/4; // // Intialize the PWM frequency and duty cycle. // g_ulFrequency = 440; g_ulDutyCycle = 50; // // Set the period of PWM1. // PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, ulPWMClock / g_ulFrequency); // // Set the pulse width of PWM1. // PWMPulseWidthSet(PWM_BASE, PWM_OUT_1, ((ulPWMClock * g_ulDutyCycle)/100) / g_ulFrequency); // // Start the timers in generator 0. // PWMGenEnable(PWM_BASE, PWM_GEN_0); }
//***************************************************************************** // // The main loop for the user interface. // //***************************************************************************** int main(void) { unsigned long ulPanel; // // If running on Rev A2 silicon, turn the LDO voltage up to 2.75V. This is // a workaround to allow the PLL to operate reliably. // if(REVISION_IS_A2) { SysCtlLDOSet(SYSCTL_LDO_2_75V); } // // Set the clocking to run at 50MHz from the PLL. // SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Set the priority of the interrupts. // IntPrioritySet(INT_CAN0, 0x00); IntPrioritySet(FAULT_SYSTICK, 0x20); // // Configure SysTick to generate an interrupt every millisecond. // SysTickPeriodSet(SysCtlClockGet() / 1000); SysTickIntEnable(); SysTickEnable(); // // Initialize the push button driver. // ButtonsInit(); // // Initialize the CAN communication channel. // CANCommInit(); // // Initialize the UART used to perform a "firmware update". // UpdateUARTInit(); // // Initialize the display. // RIT128x96x4Init(3500000); // // Add the screen-clearing widget to the widget tree. As the first widget // in the tree, this will always be drawn first, resulting in a blank // screen before anything else is drawn. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sBackground); // // Display the splash screen. // DisplaySplash(); // // Set the CAN device ID to one. // CANSetID(1); // // The "Voltage Control Mode" panel should be displayed first. // ulPanel = PANEL_VOLTAGE; // // Loop forever. // while(1) { // // Determine which panel to display. // switch(ulPanel) { // // The "Voltage Control Mode" panel should be displayed. // case PANEL_VOLTAGE: { ulPanel = DisplayVoltage(); break; } // // The "VComp Control Mode" panel should be displayed. // case PANEL_VCOMP: { ulPanel = DisplayVComp(); break; } // // The "Current Control Mode" panel should be displayed. // case PANEL_CURRENT: { ulPanel = DisplayCurrent(); break; } // // The "Speed Control Mode" panel should be displayed. // case PANEL_SPEED: { ulPanel = DisplaySpeed(); break; } // // The "Position Control Mode" panel should be displayed. // case PANEL_POSITION: { ulPanel = DisplayPosition(); break; } // // The "Configuration" panel should be displayed. // case PANEL_CONFIGURATION: { ulPanel = DisplayConfig(); break; } // // The "Device List" panel should be displayed. // case PANEL_DEV_LIST: { ulPanel = DisplayDevList(); break; } // // The "Firmware Update" panel should be displayed. // case PANEL_UPDATE: { ulPanel = DisplayUpdate(); break; } // // The "Help" panel should be displayed. // case PANEL_HELP: { ulPanel = DisplayHelp(); break; } // // The "About" panel should be displayed. // case PANEL_ABOUT: { ulPanel = DisplayAbout(); break; } } } }
//***************************************************************************** // // This example demonstrates the use of PWM for playing audio. // //***************************************************************************** int main(void) { // // If running on Rev A2 silicon, turn the LDO voltage up to 2.75V. This is // a workaround to allow the PLL to operate reliably. // if(REVISION_IS_A2) { SysCtlLDOSet(SYSCTL_LDO_2_75V); } // // Set the clocking to run directly from the crystal. // SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); SysCtlPWMClockSet(SYSCTL_PWMDIV_1); // // Enable the peripherals used by the application. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); // // Configure the GPIOs used to read the state of the on-board push buttons. // GPIOPinTypeGPIOInput(GPIO_PORTG_BASE, (GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7)); GPIOPadConfigSet(GPIO_PORTG_BASE, (GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7), GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Initialize the OLED display and print out the directions. // RIT128x96x4Init(1000000); RIT128x96x4StringDraw("Audio Playback via", 10, 16, 15); RIT128x96x4StringDraw("Class-D Amplifier", 12, 24, 15); RIT128x96x4StringDraw("Press Up for Vol+", 12, 40, 15); RIT128x96x4StringDraw("Press Down for Vol-", 6, 48, 15); RIT128x96x4StringDraw("Press Left for PCM", 10, 56, 15); RIT128x96x4StringDraw("Press Right for ADPCM", 0, 64, 15); RIT128x96x4StringDraw("Press Select to stop", 4, 72, 15); // // Initialize the Class-D amplifier driver. // ClassDInit(SysCtlClockGet()); // // Wait until the Class-D amplifier driver is done starting up. // while(ClassDBusy()) { } // // Start playback of the PCM stream. // ClassDPlayPCM(g_pucPCMData, sizeof(g_pucPCMData)); // // Set up and enable SysTick. // SysTickPeriodSet(SysCtlClockGet() / 200); SysTickEnable(); SysTickIntEnable(); // // Loop forever. // while(1) { } }
//***************************************************************************** // // This is the main example program. It checks to see that the interrupts are // processed in the correct order when they have identical priorities, // increasing priorities, and decreasing priorities. This exercises interrupt // preemption and tail chaining. // //***************************************************************************** int main(void) { unsigned long ulError; // // Set the clocking to run directly from the crystal. // SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Enable the peripherals used by this example. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // // Initialize the OLED display and write status. // RIT128x96x4Init(1000000); RIT128x96x4StringDraw("Act: Pend: ", 18, 40, 15); // // Configure the F0, D1 and D2 to be outputs to indicate entry/exit of one // of the interrupt handlers. // GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2); GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2, 0); // // Set up and enable the SysTick timer. It will be used as a reference // for delay loops in the interrupt handlers. The SysTick timer period // will be set up for one second. // SysTickPeriodSet(SysCtlClockGet()); SysTickEnable(); // // Reset the error indicator. // ulError = 0; // // Enable interrupts to the processor. // IntMasterEnable(); // // Enable the interrupts. // IntEnable(INT_GPIOA); IntEnable(INT_GPIOB); IntEnable(INT_GPIOC); // // Indicate that the equal interrupt priority test is beginning. // RIT128x96x4StringDraw("Equal Priority ", 18, 24, 15); // // Set the interrupt priorities so they are all equal. // IntPrioritySet(INT_GPIOA, 0x00); IntPrioritySet(INT_GPIOB, 0x00); IntPrioritySet(INT_GPIOC, 0x00); // // Reset the interrupt flags. // g_ulGPIOa = 0; g_ulGPIOb = 0; g_ulGPIOc = 0; g_ulIndex = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the LCD. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ulGPIOa != 3) || (g_ulGPIOb != 2) || (g_ulGPIOc != 1)) { ulError |= 1; } // // Wait two seconds. // Delay(2); // // Indicate that the decreasing interrupt priority test is beginning. // RIT128x96x4StringDraw("Dec. Priority ", 18, 24, 15); // // Set the interrupt priorities so that they are decreasing (i.e. C > B > // A). // IntPrioritySet(INT_GPIOA, 0x80); IntPrioritySet(INT_GPIOB, 0x40); IntPrioritySet(INT_GPIOC, 0x00); // // Reset the interrupt flags. // g_ulGPIOa = 0; g_ulGPIOb = 0; g_ulGPIOc = 0; g_ulIndex = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the OLED. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ulGPIOa != 3) || (g_ulGPIOb != 2) || (g_ulGPIOc != 1)) { ulError |= 2; } // // Wait two seconds. // Delay(2); // // Indicate that the increasing interrupt priority test is beginning. // RIT128x96x4StringDraw("Inc. Priority ", 18, 24, 15); // // Set the interrupt priorities so that they are increasing (i.e. C < B < // A). // IntPrioritySet(INT_GPIOA, 0x00); IntPrioritySet(INT_GPIOB, 0x40); IntPrioritySet(INT_GPIOC, 0x80); // // Reset the interrupt flags. // g_ulGPIOa = 0; g_ulGPIOb = 0; g_ulGPIOc = 0; g_ulIndex = 1; // // Trigger the interrupt for GPIO C. // HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16; // // Put the current interrupt state on the OLED. // DisplayIntStatus(); // // Verify that the interrupts were processed in the correct order. // if((g_ulGPIOa != 1) || (g_ulGPIOb != 2) || (g_ulGPIOc != 3)) { ulError |= 4; } // // Wait two seconds. // Delay(2); // // Disable the interrupts. // IntDisable(INT_GPIOA); IntDisable(INT_GPIOB); IntDisable(INT_GPIOC); // // Disable interrupts to the processor. // IntMasterDisable(); // // Print out the test results. // RIT128x96x4StringDraw("Int Priority ", 18, 24, 15); if(ulError) { RIT128x96x4StringDraw("=: P >: P <: P", 18, 40, 15); if(ulError & 1) { RIT128x96x4StringDraw("F", 36, 40, 15); } if(ulError & 2) { RIT128x96x4StringDraw("F", 72, 40, 15); } if(ulError & 4) { RIT128x96x4StringDraw("F", 108, 40, 15); } } else { RIT128x96x4StringDraw("Success. ", 18, 40, 15); } // // Finished. // while(1) { } }
//***************************************************************************** // // Print "Hello World!" to the UART on the evaluation board. // //***************************************************************************** int main(void) { //volatile uint32_t ui32Loop; // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPULazyStackingEnable(); // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // // Enable the GPIO port that is used for the on-board LED. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Enable the GPIO pins for the LED (PF2 & PF3). // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); // // Initialize the UART. // ConfigureUART(); // // Hello! // UARTprintf("Hello, world!\n"); // // We are finished. Hang around doing nothing. // while(1) { // // Turn on the BLUE LED. // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); // // Delay for a bit. // SysCtlDelay(SysCtlClockGet() / 10 / 3); // // Turn off the BLUE LED. // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); // // Delay for a bit. // SysCtlDelay(SysCtlClockGet() / 10 / 3); } }
int main(void) { unsigned int i = 0; // Clock (80MHz) SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // GPIO SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2); GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0); // UART (Serial) SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200, (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE | UART_CONFIG_WLEN_8)); UARTEnable(UART0_BASE); UARTFIFODisable(UART0_BASE); /*I2CInit(); // PCA9557 i2c_buff[0] = 0x03; i2c_buff[1] = 0x00; // 0: Output 1: Input I2CWrite(0x18, i2c_buff, 2); // IO Direction i2c_buff[0] = 0x02; i2c_buff[1] = 0x00; I2CWrite(0x18, i2c_buff, 2); // IO Polarity i2c_buff[0] = 0x01; i2c_buff[1] = 0x8F; I2CWrite(0x18, i2c_buff, 2); // Output H/L */ //initLEDs(); //initMotors(); //initEncoders(); initServos(); //initBluetooth(); //invertMotor(0); //invertMotor(1); //invertEncoder(0); // Do some tests //setMotor(0, 0.85); //setMotor(1, 0.85); setServoLimits(5, 0.35, 0.85); // Enable Interrupts IntMasterEnable(); while(1) { //for(i=0; i<12; i++) //{ setServo(5, 0.0); toggleRed(); SysCtlDelay(SysCtlClockGet()); // printf("%d\r\n", i*5); setServo(5, 0.6); toggleRed(); SysCtlDelay(SysCtlClockGet()); //} // LED On /* toggleRed(); printf("0:% 6ld 1:% 6ld\r\n", readEnc(0), readEnc(1)); SysCtlDelay(SysCtlClockGet() / 3 / 5); if (i == 10) // 5 Seconds { i2c_buff[0] = 0x01; i2c_buff[1] = 0x0F | 0x00; I2CWrite(0x18, i2c_buff, 2); // Output H/L } i++; */ /*I2CMasterSlaveAddrSet(I2C0_BASE, 0x18, false); // Set Outputs Directions I2CMasterDataPut(I2C0_BASE, 0x01); I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START); while(I2CMasterBusy(I2C0_BASE)); I2CMasterDataPut(I2C0_BASE, 0x00); I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH); while(I2CMasterBusy(I2C0_BASE)); I2CMasterSlaveAddrSet(I2C0_BASE, 0x18, false); // Set Outputs Directions I2CMasterDataPut(I2C0_BASE, 0x01); I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START); while(I2CMasterBusy(I2C0_BASE)); I2CMasterDataPut(I2C0_BASE, 0xF0); I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH); while(I2CMasterBusy(I2C0_BASE)); */ //UART1Write("A\r\n", 3); //UARTCharPut(UART1_BASE, 'B'); //UART1WriteChar(UARTCharGet(UART0_BASE)); /* for (i=0; i<8; i++) { unsigned char tmp; i2c_buff[0] = 0x84 | (i << 4); I2CWrite(0x48, i2c_buff, 1); if (I2CMasterErr(I2C0_BASE)) printf("Err: %d\r\n", (unsigned int) I2CMasterErr(I2C0_BASE)); I2CRead(0x48, &tmp, 1); if (I2CMasterErr(I2C0_BASE)) printf("Err: %d\r\n", (unsigned int) I2CMasterErr(I2C0_BASE)); printf("% 3d ", tmp); }*/ /* toggleRed(); for(i=0; i<=100; i++) { setMotor(0, 0.01 * i); setMotor(1, 0.01 * i); setMotor(2, 0.01 * i); setMotor(3, 0.01 * i); printf("%d\r\n", i); SysCtlDelay(SysCtlClockGet() / 3 / 100); } toggleRed(); for(; i>0; i--) { setMotor(0, 0.01 * i); setMotor(1, 0.01 * i); setMotor(2, 0.01 * i); setMotor(3, 0.01 * i); printf("%d\r\n", i); SysCtlDelay(SysCtlClockGet() / 3 / 100); }*/ //printf("%d\r\n", (unsigned int) (((ADCRead(3) >> 4) - 45) * 0.45)); //setServo(0, (((ADCRead(3) >> 4) - 45) * 0.45) / 100.0); /* I2CMasterSlaveAddrSet(I2C0_BASE, 0x18, false); // Set Outputs Directions I2CMasterDataPut(I2C0_BASE, 0x01); I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START); while(I2CMasterBusy(I2C0_BASE)); if (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4) == 0) I2CMasterDataPut(I2C0_BASE, 0x80); else I2CMasterDataPut(I2C0_BASE, 0x70); I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH); while(I2CMasterBusy(I2C0_BASE));*/ /*I2CMasterSlaveAddrSet(I2C0_BASE, 0x18, false); I2CMasterDataPut(I2C0_BASE, 0x00); I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND); while(I2CMasterBusy(I2C0_BASE)); I2CMasterSlaveAddrSet(I2C0_BASE, 0x18, true); I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE); while(I2CMasterBusy(I2C0_BASE)); if( (I2CMasterDataGet(I2C0_BASE) & 0x01) != 0) toggleBlue();*/ } }
//***************************************************************************** // // Send a synchronous data message and wait for the response with a timeout. // // \param psMsg the tRemoTIMsg to be sent. If successful and a reply was // received then this will also hold the reply message when this function // returns. // // This function sets the \e ui8SubSystem element to indicate this is a // synchronous message transfer. It then calls NPI_MsgWrap() to set the start // of frame and frame check bytes. Finally it puts the message in the UART // buffer, starts transmission and waits for a response. If a response is // not given false is returned. If the response was received before the timeout // then the response message is loaded into \e psMsg and true is returned. // // \return Returns false if response was not received before timeout. Returns // true and copies response to \e psMsg if response was received. // //***************************************************************************** bool NPI_SendSynchData(tRemoTIMsg *psMsg) { uint8_t *pui8Buf; uint32_t ui32Ticks; // // Cast the tRemoTIMsg to a byte array. // pui8Buf = (uint8_t *) psMsg; // // Add the proper RPC type to the header. // psMsg->ui8SubSystem &= RPC_SUBSYSTEM_MASK; psMsg->ui8SubSystem |= RPC_CMD_SREQ; // // Add the SOF and FCS bytes to the msg. // NPI_MsgWrap(psMsg); // // Clear the flag to show we do not have a response to this outgoing msg. // Clear the tick counter to start our timeout sequence. // g_vbSyncResponse = false; ui32Ticks = 0; // // Send the msg and wait for a response to come back // RemoTIUARTPutMsg(pui8Buf, psMsg->ui8Length + 5); do { // // Delay about 10 milliseconds waiting for the response. // SysCtlDelay(SysCtlClockGet() / (100 * 3)); ui32Ticks++; // // Continue waiting for the response until it comes in or we hit the // timeout limit. // }while((!g_vbSyncResponse) && (ui32Ticks < NPI_SYNC_MSG_TIMEOUT)); // //Return failure if we had a timeout // if((ui32Ticks >= NPI_SYNC_MSG_TIMEOUT) || (!g_vbSyncResponse)) { return(false); } // // Go get the response from the UART and put it into the msg buffer // RemoTIUARTGetMsg(pui8Buf, psMsg->ui8Length + 5); // // Return Success if the response came back in time. // return(true); }
//***************************************************************************** // // main loop - sets up UART1, UART 0, and the command loop to process commands // //***************************************************************************** int main(void) { int nStatus; int x; // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPUEnable(); ROM_FPULazyStackingEnable(); // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); //Setup UART1 on PB0 / PB1 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); GPIOPinConfigure(GPIO_PB0_U1RX); GPIOPinConfigure(GPIO_PB1_U1TX); GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioConfig(1, 9600, SysCtlClockGet()); ConfigureUART(); //UART0 // // Enable the UART1 interrupt. // ROM_IntEnable(INT_UART1); ROM_UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT); //Initialize LED's SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF; x = SYSCTL_RCGC2_R; //dummy cycle GPIO_PORTF_DIR_R |= 0x08; GPIO_PORTF_DEN_R |= 0x08; GPIO_PORTF_DIR_R |= 0x04; GPIO_PORTF_DEN_R |= 0x04; GPIO_PORTF_DIR_R |= 0x02; GPIO_PORTF_DEN_R |= 0x02; // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Enter an infinite loop for reading and processing commands from the // user. // Cmd_help(0,0); while(1) { // // Print a prompt to the console. Show the CWD. // UARTprintf("\n> "); // // Get a line of text from the user. // UARTgets(g_pcCmdBuf, sizeof(g_pcCmdBuf)); // // Pass the line from the user to the command processor. It will be // parsed and valid commands executed. // nStatus = CmdLineProcess(g_pcCmdBuf); // // Handle the case of bad command. // if(nStatus == CMDLINE_BAD_CMD) { UARTprintf("Bad command!\n"); } // // Handle the case of too many arguments. // else if(nStatus == CMDLINE_TOO_MANY_ARGS) { UARTprintf("Too many arguments for command processor!\n"); } // // Otherwise the command was executed. Print the error code if one was // returned. // else if(nStatus != 0) { UARTprintf("Command returned error code\n"); } } }
//***************************************************************************** // // Configure Timer0B as a 16-bit periodic counter with an interrupt // every 1ms. // //***************************************************************************** int main(void) { #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) uint32_t ui32SysClock; #endif uint32_t ui32PrevCount = 0; // // Set the clocking to run directly from the external crystal/oscillator. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal on your board. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_OSC), 25000000); #else SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); #endif // // The Timer0 peripheral must be enabled for use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // // Set up the serial console to use for displaying messages. This is // just for this example program and is not needed for Timer operation. // InitConsole(); // // Display the example setup on the console. // UARTprintf("16-Bit Timer Interrupt ->"); UARTprintf("\n Timer = Timer0B"); UARTprintf("\n Mode = Periodic"); UARTprintf("\n Number of interrupts = %d", NUMBER_OF_INTS); UARTprintf("\n Rate = 1ms\n\n"); // // Configure Timer0B as a 16-bit periodic timer. // TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PERIODIC); // // Set the Timer0B load value to 1ms. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) TimerLoadSet(TIMER0_BASE, TIMER_B, ui32SysClock / 1000); #else TimerLoadSet(TIMER0_BASE, TIMER_B, SysCtlClockGet() / 1000); #endif // // Enable processor interrupts. // IntMasterEnable(); // // Configure the Timer0B interrupt for timer timeout. // TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT); // // Enable the Timer0B interrupt on the processor (NVIC). // IntEnable(INT_TIMER0B); // // Initialize the interrupt counter. // g_ui32Counter = 0; // // Enable Timer0B. // TimerEnable(TIMER0_BASE, TIMER_B); // // Loop forever while the Timer0B runs. // while(1) { // // If the interrupt count changed, print the new value // if(ui32PrevCount != g_ui32Counter) { // // Print the periodic interrupt counter. // UARTprintf("Number of interrupts: %d\r", g_ui32Counter); ui32PrevCount = g_ui32Counter; } } }
// Initializing display void Adafruit320x240x16_ILI9325Init(void) { unsigned short usAddress, usData; // Reset global variables g_ulWait1ms = SysCtlClockGet() / (3 * 1000); // Enable GPIO peripherals SysCtlPeripheralEnable(LCD_DATA_PERIPH); SysCtlPeripheralEnable(LCD_CS_PERIPH); SysCtlPeripheralEnable(LCD_CD_PERIPH); SysCtlPeripheralEnable(LCD_WR_PERIPH); SysCtlPeripheralEnable(LCD_RD_PERIPH); SysCtlPeripheralEnable(LCD_RST_PERIPH); SysCtlPeripheralEnable(LCD_BKLT_PERIPH); // Configure pins, all output GPIOPinTypeGPIOOutput(LCD_DATA_BASE, LCD_DATA_PINS); GPIOPinTypeGPIOOutput(LCD_CS_BASE, LCD_CS_PIN); GPIOPinTypeGPIOOutput(LCD_CD_BASE, LCD_CD_PIN); GPIOPinTypeGPIOOutput(LCD_WR_BASE, LCD_WR_PIN); GPIOPinTypeGPIOOutput(LCD_RD_BASE, LCD_RD_PIN); GPIOPinTypeGPIOOutput(LCD_BKLT_BASE, LCD_BKLT_PIN); GPIOPinTypeGPIOOutput(LCD_RST_BASE, LCD_RST_PIN); // Set control pins to idle/off state LCD_CS_IDLE LCD_RD_IDLE LCD_WR_IDLE LCD_BKLT_OFF // Reset LCD LCD_RST_ACTIVE LCD_DELAY(50); LCD_RST_IDLE LCD_DELAY(50); // Talk to LCD for init LCD_CS_ACTIVE // Sync communication LCDWriteData(0); LCDWriteData(0); LCDWriteData(0); LCDWriteData(0); LCD_DELAY(50); // Process initialization sequence of display driver int i = 0; while(usInitScript[i] != ILI_STOPCMD) { usAddress = usInitScript[i++]; usData = usInitScript[i++]; if(usAddress == ILI_DELAYCMD) { LCD_DELAY(usData); } else { LCDWriteCommand(usAddress); LCDWriteData(usData); } } // Clear display of any stray pixels LCDClear(); // Done talking to LCD LCD_CS_IDLE // Turn back light on LCD_BKLT_ON return; }
int platform_init() { // Set the clocking to run from PLL #if defined( FORLM3S9B92 ) || defined( FORLM3S9D92 ) MAP_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); #else MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); #endif // Setup PIO pios_init(); // Setup SSIs spis_init(); // Setup UARTs uarts_init(); // Setup timers timers_init(); // Setup PWMs pwms_init(); #ifdef BUILD_ADC // Setup ADCs adcs_init(); #endif #ifdef BUILD_CAN // Setup CANs cans_init(); #endif #ifdef BUILD_USB_CDC // Setup USB usb_init(); #endif // Setup system timer cmn_systimer_set_base_freq( MAP_SysCtlClockGet() ); cmn_systimer_set_interrupt_freq( SYSTICKHZ ); // Setup ethernet (TCP/IP) eth_init(); // Common platform initialization code cmn_platform_init(); // Virtual timers // If the ethernet controller is used the timer is already initialized, so skip this sequence #if VTMR_NUM_TIMERS > 0 && !defined( BUILD_UIP ) // Configure SysTick for a periodic interrupt. MAP_SysTickPeriodSet( MAP_SysCtlClockGet() / SYSTICKHZ ); MAP_SysTickEnable(); MAP_SysTickIntEnable(); MAP_IntMasterEnable(); #endif MAP_FlashUsecSet( SysCtlClockGet() ); // All done return PLATFORM_OK; }
//***************************************************************************** // // Configure PWM0 for a 25% duty cycle signal running at 250Hz. This example // also shows how to invert the PWM signal every 5 seconds for 5 seconds. // //***************************************************************************** int main(void) { // // Set the clocking to run directly from the external crystal/oscillator. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal on your board. // SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Set the PWM clock to the system clock. // SysCtlPWMClockSet(SYSCTL_PWMDIV_1); // // Set up the serial console to use for displaying messages. This is // just for this example program and is not needed for Timer operation. // InitConsole(); // // Display the setup on the console. // UARTprintf("PWM ->\n"); UARTprintf(" Module: PWM0\n"); UARTprintf(" Pin: PD0\n"); UARTprintf(" Configured Duty Cycle: 25%%\n"); UARTprintf(" Inverted Duty Cycle: 75%%\n"); UARTprintf(" Features: PWM output inversion every 5 seconds.\n\n"); UARTprintf("Generating PWM on PWM0 (PD0) -> State = "); // // The PWM peripheral must be enabled for use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM); // // For this example PWM0 is used with PortD Pin0. The actual port and // pins used may be different on your part, consult the data sheet for // more information. // GPIO port D needs to be enabled so these pins can be used. // TODO: change this to whichever GPIO port you are using. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // // Configure the GPIO pin muxing to select PWM00 functions for these pins. // This step selects which alternate function is available for these pins. // This is necessary if your part supports GPIO pin function muxing. // Consult the data sheet to see which functions are allocated per pin. // TODO: change this to select the port/pin you are using. // GPIOPinConfigure(GPIO_PD0_PWM0); // // Configure the PWM function for this pin. // Consult the data sheet to see which functions are allocated per pin. // TODO: change this to select the port/pin you are using. // GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0); // // Configure the PWM0 to count up/down without synchronization. // PWMGenConfigure(PWM_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); // // Set the PWM period to 250Hz. To calculate the appropriate parameter // use the following equation: N = (1 / f) * SysClk. Where N is the // function parameter, f is the desired frequency, and SysClk is the // system clock frequency. // In this case you get: (1 / 250Hz) * 16MHz = 64000 cycles. Note that // the maximum period you can set is 2^16. // TODO: modify this calculation to use the clock frequency that you are // using. // PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, 64000); // // Set PWM0 to a duty cycle of 25%. You set the duty cycle as a function // of the period. Since the period was set above, you can use the // PWMGenPeriodGet() function. For this example the PWM will be high for // 25% of the time or 16000 clock ticks (64000 / 4). // PWMPulseWidthSet(PWM_BASE, PWM_OUT_0, PWMGenPeriodGet(PWM_BASE, PWM_OUT_0) / 4); // // Enable the PWM0 Bit0 (PD0) output signal. // PWMOutputState(PWM_BASE, PWM_OUT_0_BIT, true); // // Enable the PWM generator block. // PWMGenEnable(PWM_BASE, PWM_GEN_0); // // Loop forever while the PWM signals are generated. // while(1) { // // Print out that the level of PWM is normal. // UARTprintf("Normal \b\b\b\b\b\b\b\b"); // // This function provides a means of generating a constant length // delay. The function delay (in cycles) = 3 * parameter. Delay // 5 seconds arbitrarily. // SysCtlDelay((SysCtlClockGet() * 5) / 3); // // Invert PWM0 signal. // PWMOutputInvert(PWM_BASE, PWM_OUT_0_BIT, true); // // Print out that the level of PWM is inverted. // UARTprintf("Inverted\b\b\b\b\b\b\b\b"); // // This function provides a means of generating a constant length // delay. The function delay (in cycles) = 3 * parameter. Delay // 5 seconds arbitrarily. // SysCtlDelay((SysCtlClockGet() * 5) / 3); // // Switch PWM0 signal back to regular operation. // PWMOutputInvert(PWM_BASE, PWM_OUT_0_BIT, false); } }
/* * Function Name: UARTIntHandler * Input: none * Output: none * Description: Interrupt handler for UART Int * Example Call: UARTIntHandler(); */ void UARTIntHandler(void) { uint32_t ui32Status; ui32Status = UARTIntStatus(UART0_BASE, true); //get interrupt status UARTIntClear(UART0_BASE, ui32Status); //clear the asserted interrupts while (UARTCharsAvail(UART0_BASE)) //loop while there are chars { unsigned char a = UARTCharGetNonBlocking(UART0_BASE); if (a == 'S') { mode = 1; clearscreen(); UARTCharPut(UART0_BASE, '\r'); UARTCharPut(UART0_BASE, 'E'); UARTCharPut(UART0_BASE, 'n'); UARTCharPut(UART0_BASE, 't'); UARTCharPut(UART0_BASE, 'e'); UARTCharPut(UART0_BASE, 'r'); UARTCharPut(UART0_BASE, ' '); UARTCharPut(UART0_BASE, 't'); UARTCharPut(UART0_BASE, 'h'); UARTCharPut(UART0_BASE, 'e'); UARTCharPut(UART0_BASE, ' '); UARTCharPut(UART0_BASE, 't'); UARTCharPut(UART0_BASE, 'e'); UARTCharPut(UART0_BASE, 'm'); UARTCharPut(UART0_BASE, 'p'); UARTCharPut(UART0_BASE, ':'); UARTCharPut(UART0_BASE, ' '); unsigned char x = UARTCharGet(UART0_BASE); UARTCharPut(UART0_BASE, x); unsigned char y = UARTCharGet(UART0_BASE); UARTCharPut(UART0_BASE, y); ui32SetTempValueC = (x - '0') * 10 + (y - '0'); UARTCharPut(UART0_BASE, ' '); UARTCharPut(UART0_BASE, 'T'); UARTCharPut(UART0_BASE, 'e'); UARTCharPut(UART0_BASE, 'm'); UARTCharPut(UART0_BASE, 'p'); UARTCharPut(UART0_BASE, 'e'); UARTCharPut(UART0_BASE, 'r'); UARTCharPut(UART0_BASE, 'a'); UARTCharPut(UART0_BASE, 't'); UARTCharPut(UART0_BASE, 'u'); UARTCharPut(UART0_BASE, 'r'); UARTCharPut(UART0_BASE, 'e'); UARTCharPut(UART0_BASE, ' '); UARTCharPut(UART0_BASE, 'u'); UARTCharPut(UART0_BASE, 'p'); UARTCharPut(UART0_BASE, 'd'); UARTCharPut(UART0_BASE, 'a'); UARTCharPut(UART0_BASE, 't'); UARTCharPut(UART0_BASE, 'e'); UARTCharPut(UART0_BASE, 'd'); UARTCharPut(UART0_BASE, ' '); UARTCharPut(UART0_BASE, 't'); UARTCharPut(UART0_BASE, 'o'); UARTCharPut(UART0_BASE, ':'); UARTCharPut(UART0_BASE, ' '); UARTCharPut(UART0_BASE, x); UARTCharPut(UART0_BASE, y); UARTCharPut(UART0_BASE, '\r'); SysCtlDelay(SysCtlClockGet()); //delay 1 sec mode = 0; } else { UARTCharPutNonBlocking(UART0_BASE, a); //echo character } GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); //blink LED SysCtlDelay(SysCtlClockGet() / (1000 * 3)); //delay ~1 msec GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); //turn off LED } }
/* SysCtlDelay takes 3 instructions per loop Convert desired delay to delay loops */ void microsecdelay(unsigned long delay) { SysCtlDelay((3*delay)/(SysCtlClockGet()/1000)); }
/* ********************************************************************************************************* * BSP_DACInit (void) * * Description : Initialize the TLV320AIC3107 DAC. * * Argument(s) : None. * * Return(s) : True on success or false on error. * * Caller(s) : Sound driver. * * Note(s) : This function initializes the I2C interface and the TLV320AIC3107 DAC. * ********************************************************************************************************* */ CPU_BOOLEAN BSP_DACInit (void) { CPU_BOOLEAN bRetcode; CPU_INT08U ucTest; // Enable the GPIO port containing the I2C pins and set the SDA pin as a // GPIO input for now and engage a weak pull-down. If the daughter board // is present, the pull-up on the board should easily overwhelm // the pull-down and we should read the line state as high. SysCtlPeripheralEnable(DAC_I2CSCL_GPIO_PERIPH); GPIOPinTypeGPIOInput(DAC_I2CSCL_GPIO_PORT, DAC_I2CSDA_PIN); GPIOPadConfigSet(DAC_I2CSCL_GPIO_PORT, DAC_I2CSDA_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD); // Enable the I2C peripheral. SysCtlPeripheralEnable(DAC_I2C_PERIPH); // Delay a while to ensure that we read a stable value from the SDA // GPIO pin. If we read too quickly, the result is unpredictable. // This delay is around 2mS. SysCtlDelay(SysCtlClockGet() / (3 * 500)); // Configure the pin mux. GPIOPinConfigure(GPIO_PB2_I2C0SCL); GPIOPinConfigure(GPIO_PB3_I2C0SDA); // Configure the I2C SCL and SDA pins for I2C operation. GPIOPinTypeI2C(DAC_I2CSCL_GPIO_PORT, DAC_I2CSCL_PIN | DAC_I2CSDA_PIN); // Initialize the I2C master. I2CMasterInitExpClk(DAC_I2C_MASTER_BASE, SysCtlClockGet(), 0); // Enable the I2C peripheral. SysCtlPeripheralEnable(DAC_RESET_GPIO_PERIPH); // Configure the PH2 as a GPIO output. GPIOPinTypeGPIOOutput(DAC_RESET_GPIO_PORT, DAC_RESET_PIN); // Reset the DAC GPIOPinWrite(DAC_RESET_GPIO_PORT , DAC_RESET_PIN, 0); GPIOPinWrite(DAC_RESET_GPIO_PORT , DAC_RESET_PIN, DAC_RESET_PIN); // Reset the DAC. Check the return code on this call since we use it to // indicate whether or not the DAC is present. If the register write // fails, we assume the I2S daughter board and DAC are not present and // return false. bRetcode = BSP_DACWriteRegister(TI_SOFTWARE_RESET_R, 0x80); if(!bRetcode) { return(bRetcode); } // Codec Datapath Setup Register // ---------------------- // D7 = 1 : Fsref = 44.1-kHz // D6 = 0 : ADC Dual rate mode is disabled // D5 = 0 : DAC Dual rate mode is disabled // D[4:3] = 11 : Left DAC datapath plays mono mix of left and right channel input data // D[1:1] = 00 : Right DAC datapath is off // D0 = 0 : reserved // ---------------------- // D[7:0] = 10011010 BSP_DACWriteRegister(TI_CODEC_DATAPATH_R, 0x98); // Audio Serial Data Interface Control Register A // ---------------------- // D7 = 0 : BCLK is an input (slave mode) // D6 = 0 : WCLK (or GPIO1 if programmed as WCLK) is an input (slave mode) // D5 = 0 : Do not 3-state DOUT when valid data is not being sent // D4 = 0 : BCLK / WCLK (or GPIO1 if programmed as WCLK) will not continue to be transmitted when running in master mode if codec is powered down // D3 = 0 : Reserved. // D2 = 0 : Disable 3-D digital effect processing // D[1:0] = 00 : reserved // ---------------------- // D[7:0] = 00000000 BSP_DACWriteRegister(TI_ASDI_CTL_A_R, 0x00); // Audio Serial Data Interface Control Register B // ---------------------- // D[7:6] = 00 : Serial data bus uses I2S mode // D[5:4] = 00 : Audio data word length = 16-bits // D3 = 0 : Continuous-transfer mode used to determine master mode bit clock rate // D2 = 0 : Don’t Care // D1 = 0 : Don’t Care // D0 = 0 : Re-Sync is done without soft-muting the channel. (ADC/DAC) // ---------------------- // D[7:0] = 00000000 BSP_DACWriteRegister(TI_ASDI_CTL_B_R, 0x00); // Audio Serial Data Interface Control Register C // ---------------------- // D[7:0] = 00000000 : Data offset = 0 bit clocks // ---------------------- // D[7:0] = 00000000 BSP_DACWriteRegister(TI_ASDI_CTL_C_R, 0x00); // DAC Power and Output Driver Control Register // ---------------------- // D7 = 1 : Left DAC is powered up // D6 = 1 : Right DAC is powered up // D[5:4] = 00 : HPCOM configured as differential of HPLOUT // D[3:0] = 0 : reserved // ---------------------- // D[7:0] = 11000000 BSP_DACWriteRegister(TI_DACPOD_CTL_R, 0xC0); // Left DAC Digital Volume Control Register // ---------------------- // D7 = 0 : The left DAC channel is not muted // D[6:0] = 0 : // ---------------------- // D[7:0] = BSP_DACWriteRegister(TI_LEFT_DAC_DIG_VOL_CTL_R, 0x00); // Right DAC Digital Volume Control Register // ---------------------- // D7 = 0 : The right DAC channel is not muted // D[6:0] = 0 : // ---------------------- // D[7:0] = BSP_DACWriteRegister(TI_RIGHT_DAC_DIG_VOL_CTL_R, 0x00); // DAC_L1 to LEFT_LOP Volume Control Register // ---------------------- // D7 = 1 : DAC_L1 is routed to LEFT_LOP // D[6:0] = 0110010 (50) : Gain // ---------------------- // D[7:0] = 10110010 BSP_DACWriteRegister(TI_DAC_L1_LEFT_LOP_VOL_CTL_R, 0xA0); // LEFT_LOP Output Level Control Register // ---------------------- // D[7:4] = 0110 : Output level control = 6 dB // D3 = 1 : LEFT_LOP is not muted // D2 = 0 : Reserved. // D1 = 0 : All programmed gains to LEFT_LOP have been applied // D0 = 1 : LEFT_LOP is fully powered up // ---------------------- // D[7:0] = 00001001 BSP_DACWriteRegister(TI_LEFT_LOP_OUTPUT_LVL_CTL_R, 0xC9); // From the TLV320AIC3107 datasheet: // The following initialization sequence must be written to the AIC3107 // registers prior to enabling the class-D amplifier: // register data: // 1. 0x00 0x0D // 2. 0x0D 0x0D // 3. 0x08 0x5C // 4. 0x08 0x5D // 5. 0x08 0x5C // 6. 0x00 0x00 BSP_DACWriteRegister(0x00, 0x0D); BSP_DACWriteRegister(0x0D, 0x0D); BSP_DACWriteRegister(0x08, 0x5C); BSP_DACWriteRegister(0x08, 0x5D); BSP_DACWriteRegister(0x08, 0x5C); BSP_DACWriteRegister(0x00, 0x00); // Class-D and Bypass Switch Control Register // ---------------------- // D[7:6] = 01 : Left Class-D amplifier gain = 6.0 dB // D[5:4] = 00 : Right Class-D amplifier gain = 0.0 dB // D3 = 1 : enable left class-D channel // D2 = 0 : disable right class-D channel // D1 = 0 : disable bypass switch // D0 = 0 : disable bypass switch bootstrap clock // ---------------------- // D[7:0] = 01001000 BSP_DACWriteRegister(TI_CLASSD_BYPASS_SWITCH_CTL_R, 0x40); // Read Module Power Status Register bRetcode = BSP_DACReadRegister(TI_MODULE_PWR_STAT_R, &ucTest); if(!bRetcode) { return(bRetcode); } return(true); }