Skip to content

Commit eb85848

Browse files
MPAE-8198: Updated Receive_Control_Commands code example
1 parent 4d7d436 commit eb85848

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

.main-meta/main.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"content": {
55
"metaDataVersion": "1.1.0",
66
"name": "com.microchip.mcu8.studio.project.atmega4809-getting-started-with-usart-studio",
7-
"version": "1.0.0",
7+
"version": "1.0.1",
88
"displayName": "Getting Started with USART",
99
"projectName": "atmega4809-getting-started-with-usart-studio",
1010
"shortDescription": "This repository contains 5 bare metal code examples described in the TB3216-Getting Started with USART.",

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Getting Started with Universal Synchronous and Asynchronous Receiver and Transmitter (USART) Examples (Microchip Studio)
55

6-
This repository contains examples of bare metal source code for Universal Synchronous and Asynchronous Receiver and Transmitter (USART) as described in [TB3216-Universal Synchronous and Asynchronous Receiver and Transmitter (USART)](https://www.microchip.com/) document from Microchip. The repository contains an Microchip Studio Solution with multiple projects inside:
6+
This repository contains examples of bare metal source code for Universal Synchronous and Asynchronous Receiver and Transmitter (USART) as described in [TB3216-Getting Started with USART](https://ww1.microchip.com/downloads/en/Appnotes/TB3216-Getting-Started-with-USART-90003216B.pdf) document from Microchip. The repository contains an Microchip Studio Solution with multiple projects inside:
77

88
* [<strong>Send Hello World:</strong>](Send_Hello_World) This use case demonstrates how to send a string to the PC via serial communication using the USART peripheral (for more details, see [<strong>Send Hello World</strong>](Send_Hello_World)).
99
* [<strong>Send Formatted Strings Using 'printf':</strong>](Send_Formatted_Strings_Using_Printf) This use case shows how to send formatted strings through USART. This example sends the value of a counter every 500 ms and then increases it (for more details, see [<strong> Send Fromatted Strings Using 'printf'</strong>](Send_Formatted_String_Using_Printf)).

Receive_Control_Commands/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
This project shows how to use the Universal Synchronous and Asynchronous Receiver and Transmitter (USART) to implement a command line interface. This way, the microcontroller can receive control commands via the USART. It is convenient to use the line terminator `\r\n` as a command delimiter, so for this use case the USART will read full lines. The application can decode:
77
- **'ON'** command and will turn on an LED and reply with **'OK, LED ON.\r\n'**
88
- **'OFF'** command and will turn off an LED and reply with **'OK, LED OFF.\r\n'**
9-
- for any other command, it will reply with **'Incorrect command.\r\n'**
9+
- for any other command, it will reply with **'Type ON/OFF to control the LED.\r\n'**
1010

1111
## Related Documentation
1212
More details and code examples on the ATMEGA4809 can be found at the following links:
@@ -71,9 +71,12 @@ USART0 configuration:
7171

7272
## Demo
7373

74+
Note: open the terminal before programming the device. The help command "Type ON/OFF to control the LED." will be received.
75+
7476
<br><img src="images/demo.png" width="500">
7577

7678
In this demo, commands are sent via serial communication and the confirm messages are received in a terminal.
79+
<br>Right after initialization, the board sends the "Type ON/OFF to control the LED." message. Then, it follows the behavior described in the description of this README.
7780

7881
## Summary
7982

-5.97 KB
Loading

Receive_Control_Commands/main.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222

2323
#define F_CPU 3333333
2424
#define USART1_BAUD_RATE(BAUD_RATE) ((float)(F_CPU * 64 / (16 * (float)BAUD_RATE)) + 0.5)
25-
#define MAX_COMMAND_LEN 8
25+
#define MAX_COMMAND_LEN 8
26+
#define INIT_DELAY 10 /* delay in ms */
2627

2728
#include <avr/io.h>
2829
#include <stdio.h>
2930
#include <string.h>
31+
#include <util/delay.h>
3032

3133
void USART1_init(void);
3234
void USART1_sendChar(char c);
@@ -41,7 +43,7 @@ void USART1_init(void)
4143
{
4244
PORTC.DIR &= ~PIN1_bm;
4345
PORTC.DIR |= PIN0_bm;
44-
46+
4547
USART1.BAUD = (uint16_t)USART1_BAUD_RATE(9600);
4648

4749
USART1.CTRLB |= USART_RXEN_bm | USART_TXEN_bm;
@@ -103,7 +105,7 @@ void executeCommand(char *command)
103105
}
104106
else
105107
{
106-
USART1_sendString("Incorrect command.\r\n");
108+
USART1_sendString("Type ON/OFF to control the LED.\r\n");
107109
}
108110
}
109111

@@ -115,6 +117,10 @@ int main(void)
115117

116118
LED_init();
117119
USART1_init();
120+
121+
_delay_ms(INIT_DELAY);
122+
123+
USART1_sendString("Type ON/OFF to control the LED.\r\n");
118124

119125
while (1)
120126
{

0 commit comments

Comments
 (0)