Errors may occur while accessing hardware devices. For example, an error occurs, when an I˛C device does not respond to a transaction. The Error module provides functions to handle such error conditions.
The Error functions are declared in error.h
. The currently defined
error codes and their description is shown below.
Morse Code | Error Macro | Meaning |
---|---|---|
DOT DASH
|
ERR_I2C_NODEV
| I˛C device not present |
DASH DOT DOT DOT
|
ERR_I2C_NOACK
| I˛C device did not ack |
When any of the above errors occur, the default error handler is
activated and the error code is continuously flashed on the LED using
morse code. If the error needs to be handled and an appropriate action
to be taken, an error handler can be registered using the function
error_setcb()
.
An error handler that displays an error messages on the LCD is shown in the following example.
Listing 7.1. Error Message on LCD
#include <board.h>
#include <error.h>
#include <lcd.h>
void mycb(uint8_t ecode) __reentrant
{
lcd_puts("Error!\n");
lcd_puts(error_str(ecode));
}
int main()
{
board_init();
lcd_init();
lcd_puts("Init\n");
error_setcb(mycb);
error_set(ERR_I2C_NODEV);
return 0;
}
---