Question

help me, how can wright the code using ( atmel 7 )

( GCC C ASF Board Project ) C/C++

Equipment and Materials SAMD21 or SAMW25 Xplained Pro 1) 2) USB cable 3) PC ELVIS II board 4) Program UART Write a program thProcedure UART 1) Load your program to the SAMD21 XPRO. Connect your board to the PC using a USB cable. 2) 3) Find the COM po

Equipment and Materials SAMD21 or SAMW25 Xplained Pro 1) 2) USB cable 3) PC ELVIS II board 4) Program UART Write a program that uses the default UART interface of the SAMD21 microcontroller to communicate with over the the UART of the EDBG microcontroller. The EDBG chip will then convert the serial data and send this USB to the PC. This provides which is obviously a useful function. an interface for sending and receiving data between your SAMD21 and a PC Write C code that sends the string "Enter a temperature value" across the serial connection when the SWO button on the XPRO board is pressed. Read the value sent back when a user enters a two-digit number into the serial terminal which should be in the form of two numbers (00-99). Echo back this value to the serial port in the form, "You enter the value XX". Each time the user button is pressed, the string should be sent and you should wait until a value is entered. You will need to specify the typical attributes of the connection such as baud rate and pin connections.
Procedure UART 1) Load your program to the SAMD21 XPRO. Connect your board to the PC using a USB cable. 2) 3) Find the COM port associated with your board. You can do this by going to the device manager and looking at the attached COM devices, or you can open Command Prompt and type "mode". This will list all attached COM port devices. If your board is the only one, it will be easy to determine which one is yours. If not, unplug your device and type "mode" again to see which port is no longer listed 4) Open putty. And enter the appropriate settings for serial communication. Open the connection. 5) Press the user button and wait for the prompt. Then enter a two-digit number. 6) Check to see if the value is sent back.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

int uart_init(uart_config_t *config)
{
int status = -1;

/* USCI should be in reset before configuring - only configure once */
if (UCA0CTL1 & UCSWRST) {
size_t i;

/* Set clock source to SMCLK */
UCA0CTL1 |= UCSSEL_2;

/* Find the settings from the baud rate table */
for (i = 0; i < ARRAY_SIZE(baud_tbl); i++) {
if (baud_tbl[i].baud == config->baud) {
break;
}
}

if (i < ARRAY_SIZE(baud_tbl)) {
/* Set the baud rate */
UCA0BR0 = baud_tbl[i].UCAxBR0;
UCA0BR1 = baud_tbl[i].UCAxBR1;
UCA0MCTL = baud_tbl[i].UCAxMCTL;

/* Enable the USCI peripheral (take it out of reset) */
UCA0CTL1 &= ~UCSWRST;
status = 0;
}
}

return status;
}
typedef struct
{
uint32_t baud;
} uart_config_t;
The baud rate
struct baud_value
{
uint32_t baud;
uint16_t UCAxBR0;
uint16_t UCAxBR1;
uint16_t UCAxMCTL;
};
const struct baud_value baud_tbl[] = {
{9600, 104, 0, 0x2}
};
int uart_getchar(void)
{
int chr = -1;

if (IFG2 & UCA0RXIFG) {
chr = UCA0RXBUF;
}

return chr;
}
int uart_putchar(int c)
{
/* Wait for the transmit buffer to be ready */
while (!(IFG2 & UCA0TXIFG));

/* Transmit data */
UCA0TXBUF = (char ) c;

return 0;
}
int uart_puts(const char *str)
{
int status = -1;

if (str != NULL) {
status = 0;

while (*str != '\0') {
/* Wait for the transmit buffer to be ready */
while (!(IFG2 & UCA0TXIFG));

/* Transmit data */
UCA0TXBUF = *str;

/* If there is a line-feed, add a carriage return */
if (*str == '\n') {
/* Wait for the transmit buffer to be ready */
while (!(IFG2 & UCA0TXIFG));
UCA0TXBUF = '\r';
}

str++;
}
}

return status;
}
/* Set P1.3 interrupt to active-low edge */
P1IES |= 0x08;

/* Enable interrupt on P1.3 */
P1IE |= 0x08;

/* Configure P1.1 and P1.2 for UART (USCI_A0) */
P1SEL |= 0x6;
P1SEL2 |= 0x6;

/* Global interrupt enable */
__enable_interrupt();

watchdog_enable();

/* Initialize UART to 9600 baud */
config.baud = 9600;

if (uart_init(&config) != 0) {
while (1);
}
struct menu_item
{
const char *text;
int (*handler)(void);
};
void menu_init(const struct menu_item *menu, size_t count)
{
/* Limit menu size to 9 options */
if (count < 9) {
count = 9;
}

_current_menu = menu;
_current_menu_size = count;

display_menu();
}
void menu_run(void)
{
static unsigned int value = 0;
int c = uart_getchar();

if ((c >= '0') && (c <= '9')) {
value *= 10;
value += c - '0';
uart_putchar(c);
} else if ((c == '\n') || (c == '\r')) {
if ((value > 0) && (value <= _current_menu_size)) {
/* Invoke the callback */
if (_current_menu[value - 1].handler != NULL) {
uart_puts("\n");
if (_current_menu[value - 1].handler() != 0) {
uart_puts("\nError\n");
}
}
} else {
uart_puts("\nInvalid selection\n");
}

display_menu();
value = 0;
} else {
/* Not a valid character */
}
}
unsigned int menu_read_uint(const char *prompt)
{
unsigned int value = 0;

uart_puts(prompt);

while (1) {
int c = uart_getchar();

watchdog_pet();

if ((c >= '0') && (c <= '9')) {
value *= 10;
value += c - '0';
uart_putchar(c);
} else if ((c == '\n') || (c == '\r')) {
uart_puts("\n");
break;
} else {
/* Not a valid character */
}
}

return value;
}
static const struct menu_item main_menu[] =
{
{"Set blinking frequency", set_blink_freq},
};
static int set_blink_freq(void)
{
const unsigned int value = menu_read_uint("Enter the blinking frequency (Hz): ");

if (value > 0) {
_timer_ms = 1000 / value;
}

return (value > 0) ? 0 : -1;
}

int main(int argc, char *argv[])
{
(void) argc;
(void) argv;

if (board_init() == 0) {
int timer_handle = -1;

uart_puts("\n**********************************************");
uart_puts("\nSimply Embedded tutorials for MSP430 Launchpad");
uart_puts("\nsimplyembedded.org");
uart_puts("\nVersion: 0.9");
uart_puts("\n"__DATE__);
uart_puts("\n**********************************************");

menu_init(main_menu, ARRAY_SIZE(main_menu));

while (1) {
watchdog_pet();
menu_run();

/**
* If blinking is enabled and the timer handle is
* negative (invalid) create a periodic timer
*/
if (_blink_enable != 0 ) {
if (timer_handle < 0) {
timer_handle = timer_create(_timer_ms, 1, blink_led, NULL);
}
} else {
if (timer_handle != -1) {
timer_delete(timer_handle);
timer_handle = -1;
}
}
}
}

return 0;
}

Add a comment
Know the answer?
Add Answer to:
help me, how can wright the code using ( atmel 7 ) ( GCC C ASF Board Project ) C/C++ Equipment and Materials SAMD21 or...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT