0
0
Embedded Cprogramming~10 mins

Why serial communication is needed in Embedded C - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to send a byte over serial communication.

Embedded C
void sendByte(unsigned char data) {
    while(![1]); // Wait until transmit buffer is empty
    TXREG = data;
}
Drag options to blanks, or click blank then click option'
ARXIF
BRCIF
CTXIE
DTXIF
Attempts:
3 left
💡 Hint
Common Mistakes
Using RXIF which is for receive buffer, not transmit.
2fill in blank
medium

Complete the code to initialize serial communication at 9600 baud rate.

Embedded C
void initSerial() {
    SPBRG = [1]; // Set baud rate generator
    TXSTA = 0x24; // Enable transmitter, BRGH=1
    RCSTA = 0x90; // Enable serial port and continuous receive
}
Drag options to blanks, or click blank then click option'
A25
B12
C51
D34
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong SPBRG value causing incorrect baud rate.
3fill in blank
hard

Fix the error in the code to correctly receive a byte over serial communication.

Embedded C
unsigned char receiveByte() {
    while(![1]); // Wait until data is received
    return RCREG;
}
Drag options to blanks, or click blank then click option'
ATXIF
BTXIE
CRCIF
DRCIE
Attempts:
3 left
💡 Hint
Common Mistakes
Using TXIF which is for transmit, not receive.
4fill in blank
hard

Complete the code to handle overrun error when receiving a byte over serial communication.

Embedded C
unsigned char safeReceive() {
    if([1]) {
        [2] = 0;
        [2] = 1;
    }
    while(!RCIF);
    return RCREG;
}
Drag options to blanks, or click blank then click option'
AOERR
BCREN
CFERR
DTXEN
Attempts:
3 left
💡 Hint
Common Mistakes
Using FERR, which is cleared by reading RCREG, not by toggling CREN.
Not handling OERR properly.
5fill in blank
hard

Complete the code to enable transmit interrupt for serial communication.

Embedded C
void enableTXInt() {
    INTCONbits.[1] = 1;
    INTCONbits.[2] = 1;
    PIE1bits.[3] = 1;
}
Drag options to blanks, or click blank then click option'
AGIE
BPEIE
CTXIE
DRCIE
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting GIE or PEIE, required for any interrupts.