\doxysection{interrupt.\+ino}
\hypertarget{interrupt_8ino_source}{}\label{interrupt_8ino_source}\index{examples/interrupt/interrupt.ino@{examples/interrupt/interrupt.ino}}
\mbox{\hyperlink{interrupt_8ino}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00001}00001\ /**}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00002}00002\ \ *\ @file\ interrupt.ino}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00003}00003\ \ *\ @brief\ I2C\ interrupt\ example\ for\ the\ 7Semi\ ICM-\/20948.}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00004}00004\ \ *\ @details\ Configures\ the\ IMU\ raw-\/data-\/ready\ interrupt\ pin\ and\ counts\ ISR}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00005}00005\ \ *\ events\ on\ an\ Arduino-\/compatible\ board.}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00006}00006\ \ */}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00007}00007\ }
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00008}00008\ \#include\ <Wire.h>}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00009}00009\ \#include\ <DevLab\_ICM20948.h>}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00010}00010\ }
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00011}00011\ /**\ @brief\ I2C\ SDA\ pin\ used\ by\ the\ example\ board.\ */}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00012}00012\ \#define\ SDA\_PIN\ \ \ 6}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00013}00013\ /**\ @brief\ I2C\ SCL\ pin\ used\ by\ the\ example\ board.\ */}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00014}00014\ \#define\ SCL\_PIN\ \ \ 7}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00015}00015\ /**\ @brief\ I2C\ bus\ speed\ in\ hertz.\ */}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00016}00016\ \#define\ I2C\_FREQ\ \ 400000UL}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00017}00017\ /**\ @brief\ ICM-\/20948\ I2C\ address\ selected\ by\ the\ AD0\ pin.\ */}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00018}00018\ \#define\ ICM\_ADDR\ \ 0x69}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00019}00019\ /**\ @brief\ MCU\ pin\ connected\ to\ the\ IMU\ interrupt\ output.\ */}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00020}00020\ \#define\ PIN\_INT\ \ \ D7\ \ \ //\ ajusta\ a\ tu\ pin\ real}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00021}00021\ }
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00022}00022\ /**\ @brief\ Global\ ICM-\/20948\ driver\ instance.\ */}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00023}00023\ DevLab\_ICM20948\ imu;}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00024}00024\ }
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00025}00025\ /**\ @brief\ Print\ a\ separator\ line\ to\ Serial.\ */}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00026}00026\ void\ printLinea()\ \ \ \ \ \ \{\ Serial.println(F("{}-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/"{}));\ \}}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00027}00027\ /**\ @brief\ Print\ a\ double\ separator\ line\ to\ Serial.\ */}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00028}00028\ void\ printDobleLinea()\ \{\ Serial.println(F("{}============================================================"{}));\ \}}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00029}00029\ }
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00030}00030\ /**\ @brief\ Interrupt\ pin\ electrical\ and\ latch\ configuration.\ */}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00031}00031\ ICM20948\_IntPinConfig\ pinCfg\ =\ \{}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00032}00032\ \ \ .activeLevel\ \ \ =\ 1,}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00033}00033\ \ \ .driveMode\ \ \ \ \ =\ 0,}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00034}00034\ \ \ .latchMode\ \ \ \ \ =\ 0,}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00035}00035\ \ \ .clearMode\ \ \ \ \ =\ 1,}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00036}00036\ \ \ .fsyncActLevel\ =\ 0,}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00037}00037\ \ \ .fsyncIntEn\ \ \ \ =\ 0,}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00038}00038\ \ \ .bypassEn\ \ \ \ \ \ =\ 0}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00039}00039\ \};}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00040}00040\ }
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00041}00041\ /**\ @brief\ Interrupt\ enable\ flags\ used\ by\ this\ example.\ */}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00042}00042\ ICM20948\_IntEnableConfig\ intEn\ =\ \{}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00043}00043\ \ \ .rawDataRdyEn\ =\ 1\ \ \ //\ inicializacion\ directa}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00044}00044\ \};}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00045}00045\ }
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00046}00046\ /**\ @brief\ Number\ of\ interrupt\ events\ observed\ by\ the\ ISR.\ */}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00047}00047\ volatile\ uint32\_t\ isrCount\ =\ 0;}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00048}00048\ }
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00049}00049\ /**}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00050}00050\ \ *\ @brief\ Interrupt\ service\ routine\ for\ the\ IMU\ data-\/ready\ signal.}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00051}00051\ \ */}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00052}00052\ void\ IRAM\_ATTR\ isrHandler()\ \{}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00053}00053\ \ \ isrCount++;}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00054}00054\ \}}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00055}00055\ }
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00056}00056\ /**}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00057}00057\ \ *\ @brief\ Initialize\ I2C,\ verify\ the\ IMU,\ configure\ interrupts,\ and\ attach\ ISR.}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00058}00058\ \ */}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00059}00059\ void\ setup()\ \{}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00060}00060\ \ \ Serial.begin(115200);}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00061}00061\ \ \ delay(200);}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00062}00062\ }
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00063}00063\ \ \ Wire.begin(SDA\_PIN,\ SCL\_PIN);}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00064}00064\ }
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00065}00065\ \ \ if\ (!imu.beginI2C(ICM\_ADDR,\ Wire,\ I2C\_FREQ))\ \{}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00066}00066\ \ \ \ \ Serial.println(F("{}ERROR:\ beginI2C()\ failed."{}));}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00067}00067\ \ \ \ \ while\ (1)\ delay(200);}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00068}00068\ \ \ \}}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00069}00069\ \ \ Serial.println(F("{}ICM-\/20948\ ready."{}));}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00070}00070\ }
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00071}00071\ \ \ uint8\_t\ who;}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00072}00072\ \ \ if\ (!imu.readWhoAmI(who)\ ||\ who\ !=\ 0xEA)\ \{}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00073}00073\ \ \ \ \ Serial.println(F("{}ERROR:\ WHO\_AM\_I\ mismatch"{}));}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00074}00074\ \ \ \ \ while\ (1)\ delay(200);}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00075}00075\ \ \ \}}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00076}00076\ \ \ Serial.printf("{}WHO\_AM\_I\ =\ 0x\%02X\(\backslash\)n"{},\ who);}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00077}00077\ }
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00078}00078\ \ \ if(!imu.intInit(pinCfg))\{}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00079}00079\ \ \ \ \ Serial.println(F("{}ERROR:\ Initialization\ interruption\ failed"{}));}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00080}00080\ \ \ \ \ while(1)\ delay(200);}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00081}00081\ \ \ \};\ \ \ \ \ \ \ \ \ \ \ //\ nombre\ correcto}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00082}00082\ \ \ if(!imu.intEnableConfig(intEn))\{}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00083}00083\ \ \ \ \ Serial.println(F("{}ERROR:\ Initialization\ interruption\ failed"{}));}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00084}00084\ \ \ \ \ while(1)\ delay(200);}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00085}00085\ \ \ \}}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00086}00086\ }
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00087}00087\ \ \ attachInterrupt(digitalPinToInterrupt(PIN\_INT),\ isrHandler,\ FALLING);}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00088}00088\ \ \ Serial.println(F("{}Interrupt\ configured.\ Waiting..."{}));}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00089}00089\ \}}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00090}00090\ }
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00091}00091\ /**}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00092}00092\ \ *\ @brief\ Report\ interrupt\ events\ when\ the\ ISR\ count\ changes.}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00093}00093\ \ */}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00094}00094\ void\ loop()\ \{}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00095}00095\ \ \ static\ uint32\_t\ lastCount\ =\ 0;}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00096}00096\ }
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00097}00097\ \ \ if\ (isrCount\ !=\ lastCount)\ \{}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00098}00098\ \ \ \ \ lastCount\ =\ isrCount;}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00099}00099\ \ \ \ \ Serial.printf("{}>>>\ ISR\ disparada!\ Total:\ \%lu\(\backslash\)n"{},\ isrCount);}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00100}00100\ \ \ \}}
\DoxyCodeLine{\Hypertarget{interrupt_8ino_source_l00101}00101\ \}}

\end{DoxyCode}
