EasyManuals Logo

Texas Instruments MSP430 Student Guide

Texas Instruments MSP430
398 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #352 background imageLoading...
Page #352 background image
Lab 7c CDC ‘Simple Send’ Example
24. Once you are done watch time go by: disconnect the Terminal; Terminate the
debugger (if you didn’t do it in the last step).
25. (Optional) Review the code in this example. Here’s a bit of the code from main.c:
VOID main(VOID)
{
WDT_A_hold(WDT_A_BASE); //Stop watchdog timer
// Minimum Vcore required for the USB API is PMM_CORE_LEVEL_2
PMM_setVCore(PMM_BASE, PMM_CORE_LEVEL_2);
initPorts(); // Config GPIOS for low-power (output low)
initClocks(8000000); // MCLK=SMCLK=FLL=8MHz; ACLK=REFO=32kHz
USB_setup(TRUE,TRUE); // Init USB; if a host is present, connect
initRTC(); // Start the real-time clock
__enable_interrupt(); // Enable interrupts globally
while (1)
{
// Enter LPM0, which keeps the DCO/FLL active but shuts off the
// CPU. For USB, you can't go below LPM0!
__bis_SR_register(LPM0_bits + GIE);
// If USB is present, send time to host. Flag set every sec.
if (bSendTimeToHost)
{
bSendTimeToHost = FALSE;
convertTimeBinToASCII(timeStr);
// This function begins the USB send operation, and immediately
// returns, while the sending happens in the background.
// Send timeStr, 9 bytes, to intf #0 (which is enumerated as a
// COM port). 1000 retries. (Retries will be attempted if the
// previous send hasn't completed yet). If the bus isn't present,
// it simply returns and does nothing.
if (cdcSendDataInBackground(timeStr, 9, CDC0_INTFNUM, 1000))
{
_NOP(); // If it fails, it'll end up here. Could happen if
// the cable was detached after the connectionState()
} // check, or if somehow the retries failed
}
} //while(1)
} //main()
// Convert the binary globals hour/min/sec into a string, of format "hr:mn:sc"
// Assumes str is an nine-byte string.
VOID convertTimeBinToASCII(BYTE* str)
{
BYTE hourStr[2], minStr[2], secStr[2];
convertTwoDigBinToASCII(hour, hourStr);
convertTwoDigBinToASCII(min, minStr);
convertTwoDigBinToASCII(sec, secStr);
str[0] = hourStr[0];
str[1] = hourStr[1];
str[2] = ':';
str[3] = minStr[0];
str[4] = minStr[1];
str[5] = ':';
str[6] = secStr[0];
str[7] = secStr[1];
str[8] = '\n';
}
7 - 40 MSP430 Workshop - USB Devices

Table of Contents

Other manuals for Texas Instruments MSP430

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Texas Instruments MSP430 and is the answer not in the manual?

Texas Instruments MSP430 Specifications

General IconGeneral
BrandTexas Instruments
ModelMSP430
CategoryMicrocontrollers
LanguageEnglish

Related product manuals