<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Vicara Hardware University - Medium]]></title>
        <description><![CDATA[Vicara brings you a platform to learn hardware development, no matter what stage you’re at. Beginners to Pros, you’re all welcome here - Medium]]></description>
        <link>https://medium.com/vicara-hardware-university?source=rss----2078122dd7e9---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Vicara Hardware University - Medium</title>
            <link>https://medium.com/vicara-hardware-university?source=rss----2078122dd7e9---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 16:42:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/vicara-hardware-university" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Arduino — WDT]]></title>
            <link>https://medium.com/vicara-hardware-university/arduino-wdt-a4a3e2f96ca4?source=rss----2078122dd7e9---4</link>
            <guid isPermaLink="false">https://medium.com/p/a4a3e2f96ca4</guid>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[diy]]></category>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[arduino-uno]]></category>
            <category><![CDATA[watchdog-timer]]></category>
            <dc:creator><![CDATA[Aditi Shah]]></dc:creator>
            <pubDate>Mon, 18 Jan 2021 12:07:12 GMT</pubDate>
            <atom:updated>2021-01-18T12:07:12.130Z</atom:updated>
            <content:encoded><![CDATA[<h3>Arduino — WDT</h3><p>A watchdog timer (WDT) is a hardware timer that automatically generates a system reset if the main program neglects to periodically service it. It is often used to automatically reset an embedded device that hangs because of a software or hardware fault. The Arduino Uno board has an ATmega328P chip as its controlling unit, which has a Watchdog Timer that helps the system recover from scenarios when the system hangs or freezes due to errors in the code or due to conditions that may arise due to hardware issues.</p><p><em>How does the Watchdog timer work?</em></p><p>The watchdog timer uses an internal 128kHz clock source and needs to be configured according to the need of the application. When enabled, it starts counting from 0 to a value selected by the user. If the watchdog timer is not reset by the time it reaches the user-selected value, the timer resets the microcontroller.</p><p>The main program usually has a loop that it constantly goes through performing various functions. The watchdog timer is loaded with an initial value greater than the worst-case time delay through the main program loop, so each time it goes through the main loop the code resets the watchdog timer. If a fault occurs and the main program does not get back to reset the timer before it counts down to zero, an interrupt is generated to reset the processor. This way, the watchdog timer can detect a fault on an unattended Arduino program and attempt corrective action with a reset. After the reset, a register can also be read to determine if the watchdog timer generated the reset or if it was a normal reset. This register on the Arduino is called the Watchdog Reset Flag Register (WDRF).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/0*Qhu2Cjiho8e4ih7P" /></figure><p>The ATmega328P watchdog timer can be configured for 10 different time settings (the time after which the watchdog timer overflows, thus causing a reset). The various times are: 16ms, 32ms, 64ms, 0.125s, 0.25s, 0.5s, 1s, 2s, 4s and 8s.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/0*Aa5kIpS7aptDmNN9" /></figure><p>Now that we have a basic idea of how the timer works, to learn how to configure it. We’ll use a simple example of the on-board LED blinking on the Arduino UNO.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*egYYbNF5MyfFr6eFZ4KkyA.png" /></figure><p>Once you run the aforementioned program, the LED on board will blink for a certain time before entering the while loop. The while loop here substitutes for a system in the hanged state. Since the watchdog timer is not reset in the while loop, the timer causes a system reset and the LED starts blinking again before the system hangs and restarts again. This keeps continuing in a loop.</p><p>Note: The watchdog timer is disabled at the start of the code and a delay of 3 seconds is used before enabling the timer. The delay is important in order to let the bootloader in Arduino to check if a new code is being uploaded and give it time to burn the code into the flash.</p><p>In this blog, we learned about the Watchdog timer in the Arduino UNO, how it works, and saw a simple sketch to enable it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4a3e2f96ca4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vicara-hardware-university/arduino-wdt-a4a3e2f96ca4">Arduino — WDT</a> was originally published in <a href="https://medium.com/vicara-hardware-university">Vicara Hardware University</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Arduino — Interrupts]]></title>
            <link>https://medium.com/vicara-hardware-university/arduino-interrupts-6ad0c44f7e16?source=rss----2078122dd7e9---4</link>
            <guid isPermaLink="false">https://medium.com/p/6ad0c44f7e16</guid>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[interrupt]]></category>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[diy]]></category>
            <category><![CDATA[arduino-uno]]></category>
            <dc:creator><![CDATA[Aditi Shah]]></dc:creator>
            <pubDate>Mon, 18 Jan 2021 12:03:01 GMT</pubDate>
            <atom:updated>2021-01-18T12:03:01.540Z</atom:updated>
            <content:encoded><![CDATA[<h3>Arduino — Interrupts</h3><p>An interrupt is a signal that tells the processor to immediately stop its current task and handle another high priority processing. This high priority processing is called an Interrupt Handler/Interrupt Service Routine. Almost every electronic device comes across a scenario where an interrupt needs to ‘interrupt’ the regular process and attend to an important task at hand. So technically, interrupts are a mechanism by which an I/O or an instruction can suspend the normal execution of the processor and get serviced since it has a high priority. Once that task has been wrapped up, it goes back to doing whatever the initial task.</p><p><em>How do interrupts work?</em></p><p>Interrupts call an external function which is commonly called the interrupt service routine (ISR) so that when an external interrupt occurs, the processor first executes the code present in the ISR and then reverts to the state where it left the normal execution.</p><p>ISR has the following syntax in Arduino: <em>attachInterrupt(digitalPinToInterrupt(pin), ISR, mode)</em></p><p><em>digitalPinToInterrupt(pin</em>): In Arduino Uno, the pins used for interrupt are 2 &amp; 3. You need to specify the input pin that is used for external interrupt out here.</p><p><em>ISR</em>: It’s a function that’s called when an external interrupt is done.</p><p><em>Mode</em>: The type of transition to trigger the interrupt on, e.g falling, rising etc.</p><ul><li>Rising — To trigger an interrupt when the pin transits from LOW to HIGH.</li><li>Falling — To trigger an interrupt when the pin transits from HIGH to LOW.</li><li>Change — To trigger an interrupt when the pin transits from either LOW to HIGH or HIGH to LOW.</li><li>LOW — To trigger the interrupt when the pin is LOW.</li></ul><p><em>Types of Interrupts</em></p><p>There are two types of interrupts:</p><ul><li>Hardware Interrupts — They occur in response to an external event, such as an external interrupt pin going high or low.</li><li>Software Interrupts — They occur in response to an instruction sent from the software. Timer interrupts are software interrupts.</li></ul><p>Now let’s see how to use the Arduino interrupts using the functions that are available in the Arduino IDE. We’ll be using the attach interrupt function to initialize the interrupt and specify the Arudino pin which will be used to do so. The function takes two arguments as an input — one is the pin which is used to trigger the external interrupt and the second argument is the function name which you want to call upon every interrupt. The last argument is for the mode of interrupt that you’re using.</p><p>We’ll be using an example of the LED blinking to understand how the interrupt function works. Make the connections according to the following diagram:</p><p>Components required:</p><ol><li>Arduino Uno</li><li>Breadboard</li><li>Jumper wires</li><li>2 LEDs</li><li>Push Button</li><li>1K Resistor</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/0*siS6DVGj_74iXIx8" /></figure><p>Once you’re done with the connections, you can use the following sketch and upload it on the Arduino.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/393/0*aNywvBzIep7zHLiw" /></figure><p>The LED is attached to Pin 13 and a push-button is attached on the interrupt pin 2. So when the button is pushed up, the interrupt is triggered and there’s a change in the state. But if it&#39;s not pushed up, there’s no change and the loop continues. The ISR function is named ‘blink’, and the mode is set to ‘change’ so that whenever there’s a rise or fall, the interrupt is triggered. The ISR is used to change the state of the LED, so whenever the button is pushed or the interrupt is called the LED glows.</p><p>In this blog, we learned about what interrupts are, their different modes, types, and the functions that are required to trigger them. We also saw an example to understand how an interrupt is triggered and how exactly it works.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ad0c44f7e16" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vicara-hardware-university/arduino-interrupts-6ad0c44f7e16">Arduino — Interrupts</a> was originally published in <a href="https://medium.com/vicara-hardware-university">Vicara Hardware University</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Arduino — ADC]]></title>
            <link>https://medium.com/vicara-hardware-university/arduino-adc-2b1df1541ca9?source=rss----2078122dd7e9---4</link>
            <guid isPermaLink="false">https://medium.com/p/2b1df1541ca9</guid>
            <category><![CDATA[arduino-uno]]></category>
            <category><![CDATA[cad]]></category>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[diy]]></category>
            <dc:creator><![CDATA[Aditi Shah]]></dc:creator>
            <pubDate>Mon, 18 Jan 2021 11:57:05 GMT</pubDate>
            <atom:updated>2021-01-18T11:57:05.661Z</atom:updated>
            <content:encoded><![CDATA[<h3>Arduino — ADC</h3><p>The Analog to Digital converter in the Arduino Uno is a very useful feature that converts an analog voltage into digital and gives it to the microcontroller. By converting the analog value to digital ones, we can start using electronics to interface to the analog world around us. For example, when we interface sensors or need to integrate biometric applications — the output of the sensor is most of the time analog in nature, but the microcontroller processes digital signals. So, for such scenarios, we use ADC that acts as a mediator between the sensor and microcontroller.</p><p><em>ADC in Arduino Uno</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/0*_cnXZb8Pje4fXC45" /></figure><p>The Arduino Uno has 6 onboard ADC channels which can be used to read analog signals in the 0–5 V range. It has a 10 bit ADC, which implies that it’ll give a digital value in the range of 0–1023 (2¹⁰). This is called the resolution, which indicates the number of discrete values it can produce over the range of analog values.</p><p>Digital Output calculation</p><p>ADC Resolution = Vref/((2^n)-1)</p><p>Digital Output = Vin/Resolution</p><p>Where, Vref — The reference voltage is the maximum value that the ADC can convert and 2^n stands for the n-bit ADC (in this case 10).</p><p>For example, if the Vref is 5V, and Vin is 5V the Digital O/P value = 1023(10 bit)</p><p><em>Arduino ADC functions</em></p><p>analogRead (pin)<em> — </em>This function is used to read the analog values from the specified analog pin and returns the corresponding digital values.</p><p>analogReference (type) — This is used for configuring the reference voltage used for analog input.</p><p>Now that we’re familiar with the ADC functionalities, let’s get started with a simple program that’ll help us understand the concept better. We’ll write a simple sketch to read varying analog values that are generated using a potentiometer when connected to the A0 analog channel. The digital values which we obtain from the Arduino ADC will be displayed on the serial monitor.</p><p>Connect the potentiometer in the following manner:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*6SYA7e0NMoLgXudR" /></figure><p>Once you’ve made the above connections, upload the following sketch in the IDE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*e-x6exyRvGUtNifOSCe_xw.png" /></figure><p>Compile and upload the code on the Arduino IDE. Once the code gets uploaded, slowly turn the potentiometer, increasing the values from 0V to 5V, and then slowly decrease it back. You should be able to see the corresponding digital values in the serial monitor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*HdvfBu-A1qQ-d2QsDqTkbA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/0*lpnYpLh9irb0_5kE" /></figure><p>The ADC provides a digital output that is proportional to each analog value, to obtain the corresponding voltage, you can use the following formula:</p><p>Aout = digital value*(Vref/2^n-1)</p><p>In this blog, we covered the Analog to Digital converter in the Arduino Uno board, learned how to obtain the digital values from analog inputs, and tried out a simple example with a potentiometer. Now you can easily use any sensor or application that consists of analog outputs and get the respective digital values.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b1df1541ca9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vicara-hardware-university/arduino-adc-2b1df1541ca9">Arduino — ADC</a> was originally published in <a href="https://medium.com/vicara-hardware-university">Vicara Hardware University</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Arduino — SPI]]></title>
            <link>https://medium.com/vicara-hardware-university/arduino-spi-c922d157edf0?source=rss----2078122dd7e9---4</link>
            <guid isPermaLink="false">https://medium.com/p/c922d157edf0</guid>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[spi]]></category>
            <category><![CDATA[serial-communication]]></category>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[arduino-uno]]></category>
            <dc:creator><![CDATA[Aditi Shah]]></dc:creator>
            <pubDate>Mon, 18 Jan 2021 11:48:49 GMT</pubDate>
            <atom:updated>2021-01-18T11:48:49.180Z</atom:updated>
            <content:encoded><![CDATA[<h3>Arduino — SPI</h3><p>Serial Peripheral Interface (SPI) is a synchronous serial data protocol used by microcontrollers for communicating with one or more peripheral devices quickly over short distances. It can also be used for communication between two microcontrollers.</p><p>In an SPI connection, there is always a master device (usually a microcontroller) that controls the peripheral devices.</p><p><em>SPI uses the following four wires:</em></p><p>SCK − This is the serial clock driven by the master that synchronizes the data transmission.</p><p>MOSI − This is the master output/slave input driven by the master.</p><p>MISO − This is the master input/slave output driven by the master.</p><p>SS − This is the pin on each device that the master can use to enable/disable specific devices.</p><p>When a device’s Slave Select pin is low, it communicates with the master. When it’s high, it ignores the master. This allows you to have multiple SPI devices sharing the same MISO, MOSI, and CLK lines.</p><p><em>SPI has four modes of operations:</em></p><p>Mode 0 (the default) − Clock is low (CPOL = 0), and the data is sampled on the transition from low to high (leading edge) (CPHA = 0).</p><p>Mode 1 − Clock is low (CPOL = 0), and the data is sampled on the transition from high to low (trailing edge) (CPHA = 1).</p><p>Mode 2 − Clock is high (CPOL = 1), and the data is sampled on the transition from high to low (leading edge) (CPHA = 0).</p><p>Mode 3 − Clock is high (CPOL = 1), and the data is sampled on the transition from low to high (trailing edge) (CPHA = 1).</p><p><em>SPI Communication in Arduino</em></p><p>The following figure shows the pins in Arduino UNO which are used for SPI communication.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/0*i_iF3CJQn96OZJ0W" /></figure><p>Now, we’ll look at an example of SPI communication between two Arduinos. We’ll be configuring one Arduino as a master and another Arduino board as a slave. Following is the diagram for the connections between both the boards.</p><p>Note: The ground connection is common.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*OsAE4E7j8o911lg0" /></figure><p><strong>Arduino SPI as a Master device</strong></p><p>The Master unit sends ‘Hello World’ to the slave.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*6o2MR8AYMtCAqJJi" /></figure><p><strong>Arduino SPI as a Slave</strong></p><p>The slave device waits for the data, as soon as data arrives, the process variable becomes true indicating there is data in the buffer. In the main loop, we read this buffer and send it to the serial terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/0*WaQEaJe4_x1NNTRm" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*0_mwOM2dHuVqEIBfeMfmSA.png" /></figure><p>Now let’s look at the functions that we used for the SPI communication between both boards.</p><ul><li>SPI.begin() − This function initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low, and SS high.</li><li>SPI.setClockDivider(divider) − This sets the SPI clock divider relative to the system clock. On AVR based boards, the dividers available are 2, 4, 8, 16, 32, 64, or 128. The default setting is SPI_CLOCK_DIV4, which sets the SPI clock to one-quarter of the frequency of the system clock (5 Mhz for the boards at 20 MHz). The divider could be (SPI_CLOCK_DIV2, SPI_CLOCK_DIV4, SPI_CLOCK_DIV8, SPI_CLOCK_DIV16, SPI_CLOCK_DIV32, SPI_CLOCK_DIV64, SPI_CLOCK_DIV128).</li><li>SPI.transfer(val) − SPI transfer is based on simultaneously sending and receiving data: the received data is returned in receivedVal.</li><li>SPI.attachInterrupt(handler) − This function is called when a slave device receives data from the master.</li><li>SPI.beginTransaction(SPISettings(speedMaximum, dataOrder, dataMode)) − Initializes the SPI bus using the defined SPI settings where, speedMaximum is the clock, dataOrder(MSBFIRST or LSBFIRST) and dataMode is (SPI_MODE0, SPI_MODE1, SPI_MODE2, or SPI_MODE3).</li></ul><p>Once you’ve compiled and uploaded the respective programs on both the boards, you’ll be able to see ‘Hello World’ on the serial monitor of the slave.</p><p>In this blog, we went through SPI communication in an Arduino board, its different modes of operations and saw a simple example that implemented the SPI communications protocol.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c922d157edf0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vicara-hardware-university/arduino-spi-c922d157edf0">Arduino — SPI</a> was originally published in <a href="https://medium.com/vicara-hardware-university">Vicara Hardware University</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Arduino — I2C]]></title>
            <link>https://medium.com/vicara-hardware-university/arduino-i2c-741050f17396?source=rss----2078122dd7e9---4</link>
            <guid isPermaLink="false">https://medium.com/p/741050f17396</guid>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[i2c]]></category>
            <category><![CDATA[arduino-uno]]></category>
            <category><![CDATA[serial-communication]]></category>
            <dc:creator><![CDATA[Aditi Shah]]></dc:creator>
            <pubDate>Mon, 18 Jan 2021 06:09:47 GMT</pubDate>
            <atom:updated>2021-01-18T06:11:09.342Z</atom:updated>
            <content:encoded><![CDATA[<h3>Arduino — I2C</h3><p>The term I2C stands for ‘Inter-Integrated Circuits’. It’s normally denoted as I2C or I squared C or even as 2-wire protocol (TWI) in some instances — all indicative of the same. I2C is a synchronous communication protocol, unlike the UART; synchronous implies that both the devices that are sharing the information share a common clock signal. It consists of only two wires to share information, out of which one is used for the clock signal and the other one is used for sending and receiving data.</p><p><em>How does I2C work?</em></p><p>I2C communication protocol was first introduced by Philips. As mentioned earlier, it uses two wires which are connected across both the devices, wherein one device is called the master and the other device is called a slave. Communication always occurs between a Master and a Slave. One of the advantages of I2C communication is that it allows more than one slave to be connected to the Master.</p><p>The communication takes place through two wires namely Serial Clock (SCL) and Serial Data (SDA).</p><p>Serial Clock (SCL): Shares the clock signal generated by the master with the slave</p><p>Serial Data (SDA): Sends the data to and fro between the master and slave.</p><p>Note: At any given time only the master will be able to initiate the communication.</p><p><em>Where is I2C communication used?</em></p><p>I2C communication is used only for short-distance communication. It is mainly used to communicate with a sensor or other devices that need to send information to a master device and comes in handy when a microcontroller has to communicate with other slave modules using a minimum set of wires.</p><p><em>I2C in Arduino</em></p><p>The following image shows the I2C pins in the Arduino UNO.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*VSRRe19SWIdjDFVz" /></figure><p>The Arduino Analog pins that are used for I2C communication:</p><p>SDA — A4</p><p>SCL — A5</p><p>Now that we have an idea about the I2C communication, let’s get familiarised with the Wire library with the help of a simple example. Using the following sketch, we’ll learn how to read the Device ID of a BMP280 Pressure Sensor with the help of the I2C communication protocol in Arduino.</p><p>Components required:</p><ol><li>Arduino Uno</li><li>BMP 280 Temperature &amp; Pressure sensor</li><li>Jumper wires</li></ol><p>Make the following connections:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*p1t5BHAmi4_5LdulUubzHw.png" /><figcaption>Image: Fritzig</figcaption></figure><p>Note: Connecting SDO to the Ground, will result in slave address (0x76).</p><p>Once you’re done with these connections, upload the following sketch in the Arduino IDE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/0*yNCYF2Yax2B9e33Q" /></figure><p>Let’s go through a few of the functions that we’ve used from the Wire library:</p><ol><li>Wire.begin() — This function initiates the Wire library and joins the bus as a master or slave. In this case, the sensor is the slave and the Uno board is the master.</li><li>Wire.beginTransmission (intAddress) — This function begins transmission to the I2C slave device with the given address. It also queues the bytes for transmission with the write function and transmits them by calling endTransmission ().</li><li>Wire.write() — This writes the data from a slave device in response to a request from the master.</li><li>Wire.endTransmission() — This ends a transmission to a slave device that was started by beginTransmission() and transmits the bytes that were queued by write().</li><li>Wire.requestFrom(address, quantity, stop) — It is used by the master to request bytes from a slave device and then the bytes may be retrieved with the available() and read() functions.</li><li>Wire.read() — Reads a byte that was transmitted from a slave device to a master after a call to requestFrom() was transmitted from a master to a slave.</li><li>Wire.available() -Returns the number of bytes available for retrieval with read().</li></ol><p>The program once compiled, displays the device ID of the slave i.e the sensor on the serial monitor, using the I2C communication protocol. You can also explore reading the temperature values from the sensor.</p><p>In this blog, we went through I2C communication, how it works, where it&#39;s used, and saw a simple sketch to implement the protocol.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=741050f17396" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vicara-hardware-university/arduino-i2c-741050f17396">Arduino — I2C</a> was originally published in <a href="https://medium.com/vicara-hardware-university">Vicara Hardware University</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dialog DA14531 — WDT]]></title>
            <link>https://medium.com/vicara-hardware-university/dialog-da14531-wdt-cb5437b44af6?source=rss----2078122dd7e9---4</link>
            <guid isPermaLink="false">https://medium.com/p/cb5437b44af6</guid>
            <category><![CDATA[microcontrollers]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[electronics]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[bluetooth-low-energy]]></category>
            <dc:creator><![CDATA[Gowtham TS]]></dc:creator>
            <pubDate>Wed, 13 Jan 2021 10:50:22 GMT</pubDate>
            <atom:updated>2021-01-13T10:50:22.545Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dialog DA14531 — WDT</h3><p>A watchdog timer (WDT) is used to help the system recover from any anomalies/failures. It is a hardware timer which resets the system when it overflows. The system needs to reset the watchdog timer before it “times out”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/0*WX6JiGY5Vkek8uMT.png" /></figure><h3>Project setup</h3><p>Any of the older projects can be used for this tutorial. They are available on Github at <a href="https://github.com/vicara-hq/da14531-tutorials">https://github.com/vicara-hq/da14531-tutorials</a></p><h3>Hardware overview</h3><p>We will use a DA145xx Pro motherboard with a DA14531 Tiny module daughterboard.</p><h3>Code Overview</h3><p>Out of all the peripherals the DA14531 provides, the WDT is the easiest peripheral to use. The Dialog SDK6 has 2 preprocessor definitions which control the working of the Watchdog Timer. They can be found in the da1458x_basic_config.h file.</p><pre>/****************************************************************************************************************/<br>/* Enables WatchDog timer.                                                                                      */<br>/****************************************************************************************************************/<br>#define CFG_WDOG</pre><pre>/****************************************************************************************************************/<br>/* Watchdog timer behavior in production mode:                                                                  */<br>/*     Flag is not defined: Watchdog timer generates NMI at value 0.                                            */<br>/*     Flag is defined    : Watchdog timer generates a WDOG (SYS) reset at value 0.                             */<br>/****************************************************************************************************************/<br>#undef CFG_WDG_TRIGGER_HW_RESET_IN_PRODUCTION_MODE</pre><p>When CFG_WDOG is defined, the Watchdog timer is enabled. The pre configured duration for the WDT is 2048 ms which is ~2 seconds.</p><blockquote>Note: The configuration files do not provide any options to change the WDT period but it can be changed by modifying WATCHDOG_DEFAULT_PERIOD in arch_wdg.h . I have not tested this change and cannot assure that this will not cause any other problems.</blockquote><p>CFG_WDG_TRIGGER_HW_RESET_IN_PRODUCTION_MODE defines the behaviour of a WDT overflow when the project is built in Production mode i.e. CFG_DEVELOPMENT_DEBUG is undefined. If CFG_WDG_TRIGGER_HW_RESET_IN_PRODUCTION_MODE is defined, it generates a system reset. If it’s not defined, a Non Maskable Interrupt is generated which might store some data related to the fault before triggering a system reset.</p><p>If the project is in Debug mode, the execution of the code halts and does not reset. This allows a debugger to be attached and check what has caused the error.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb5437b44af6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vicara-hardware-university/dialog-da14531-wdt-cb5437b44af6">Dialog DA14531 — WDT</a> was originally published in <a href="https://medium.com/vicara-hardware-university">Vicara Hardware University</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dialog DA14531 — Interrupts]]></title>
            <link>https://medium.com/vicara-hardware-university/dialog-da14531-interrupts-c3b0dc5d9e00?source=rss----2078122dd7e9---4</link>
            <guid isPermaLink="false">https://medium.com/p/c3b0dc5d9e00</guid>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[bluetooth-low-energy]]></category>
            <category><![CDATA[microcontrollers]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[electronics]]></category>
            <dc:creator><![CDATA[Gowtham TS]]></dc:creator>
            <pubDate>Tue, 12 Jan 2021 09:16:38 GMT</pubDate>
            <atom:updated>2021-01-12T09:16:38.712Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dialog DA14531 — Interrupts</h3><p>Interrupts are an essential part of every microcontroller and microprocessor. If interrupts didn’t exist, then the CPU will have to keep checking if the data or peripheral it is waiting on is ready for some operation. An interrupt instead notifies the CPU that the specific peripheral has something of use which requires it’s attention.</p><p>All ARM Cortex cores have a peripheral called the <strong>N</strong>ested <strong>V</strong>ector <strong>I</strong>nterrupt <strong>C</strong>ontroller(NVIC).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*bNS-_-bi-uKHd05addqR7g.png" /></figure><p>The NVIC allows a specific number of interrupts to be defined and it also allows the assigning of priorities for these interrupts. The NVIC ensures that a lower priority interrupt cannot preempt a higher priority interrupt. Whereas, if a higher priority interrupt is triggered after a lower priority interrupt, the higher priority interrupt is serviced and then CPU returns to the non interrupt state without completing the execution of the lower priority interrupt.</p><h3>Project setup</h3><p>The project with the code for this tutorial is available on Github at <a href="https://github.com/vicara-hq/da14531-tutorials">https://github.com/vicara-hq/da14531-tutorials</a></p><p>Download the project and copy it. The project has to be placed inside the Dialog SDK6 folder. Navigate to <em>&lt;SDK6_ROOT&gt;/projects/target_apps/template </em>and paste it in this folder. The project is a modified version of the <em>empty_peripheral_template </em>project provided by Dialog. But to keep this tutorial series as open source as possible, all the following steps will use the SmartSnippets Studio.</p><h3>Hardware overview</h3><p>We will use a DA145xx Pro motherboard with a DA14531 Tiny module daughterboard with a STEVAL-MKI160V1. The hardware setup is similar to the <a href="https://medium.com/vicara-hardware-university/dialog-da14531-i2c-c2f6d12d0a8d">Dialog DA14531 I2C blog</a> with one addition to the circuit. The STEVAL-MKI160V1 is an evaluation kit for the LSM6DS3, which is a 6-axis IMU. Other than this, we will also need a few jumpers, a breadboard and 2 4.7 kOhm resistors. If you cannot find 4.7 kOhm resistors, you can also try resistors between 1 kOhm to 10 kOhm but this might affect the working of the circuit.</p><p>The LSM6DS3 has 2 configurable interrupt pins which can be triggered by a variety of functions in the LSM6DS3. We will use the INT1 pin to find when new data is available to read.</p><p>Connect these components according to the below circuit diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z7SNMfjcksb0PMJXfHgyCw.png" /></figure><blockquote>Note: VCC in the circuit refers to 3V</blockquote><h3>Code Overview</h3><p>In this tutorial, we will use interrupts to obtain Accelerometer data from the LSM6DS3. The LSM6DS3 will configured to set the INT1 pin when new accelerometer and gyroscope data is available. We will use ST’s standard C drivers to interface with the LSM6DS3. The repository for the drivers can be found <a href="https://github.com/STMicroelectronics/STMems_Standard_C_drivers">here</a>.</p><p>The driver has an device structure which requires the user to provide 3 inputs: A read function, a write function and a handle. The read and write functions can be in I2C or in SPI. The handle is the handle structure for the peripheral used to communicate with the LSM6DS3(It can be null too).</p><p>Below are the I2C read and write functions:</p><pre>int32_t platform_i2c_write(void * handle, uint8_t reg, uint8_t * bufp,<br>  uint16_t len) {</pre><pre>i2c_abort_t abort_code;<br>  i2c_master_transmit_buffer_sync( &amp;reg, 1, &amp;abort_code, I2C_F_NONE);<br>  i2c_master_transmit_buffer_sync(bufp, len, &amp;abort_code, I2C_F_ADD_STOP);<br>  return 0;<br>}</pre><pre>int32_t platform_i2c_read(void * handle, uint8_t reg, uint8_t * bufp,<br>  uint16_t len) {<br>  i2c_abort_t abort_code;<br>  i2c_master_transmit_buffer_sync( &amp;reg, 1, &amp;abort_code, I2C_F_NONE);<br>  i2c_master_receive_buffer_sync(bufp, len, &amp;abort_code, I2C_F_ADD_STOP);</pre><pre>return 0;<br>}</pre><p>In the <em>periph_setup() </em>function in the user_periph_setup.c file, we initialize the I2C peripheral and LSM6DS3 driver.</p><pre>static<br>const i2c_cfg_t i2c_cfg = {<br>  .clock_cfg.ss_hcnt = I2C_SS_SCL_HCNT_REG_RESET,<br>  .clock_cfg.ss_lcnt = I2C_SS_SCL_LCNT_REG_RESET,<br>  .clock_cfg.fs_hcnt = I2C_FS_SCL_HCNT_REG_RESET,<br>  .clock_cfg.fs_lcnt = I2C_FS_SCL_LCNT_REG_RESET,<br>  .restart_en = I2C_RESTART_ENABLE,<br>  .speed = I2C_SPEED_FAST,<br>  .mode = I2C_MODE_MASTER,<br>  .addr_mode = I2C_ADDRESSING_7B,<br>  .address = 0x6A,<br>  .tx_fifo_level = 1,<br>  .rx_fifo_level = 1,<br>};</pre><pre>i2c_init(&amp;i2c_cfg);<br> <br> // LSM6DS3 driver init<br> dev_ctx.write_reg = platform_i2c_write;<br> dev_ctx.read_reg = platform_i2c_read;<br> dev_ctx.handle = NULL;</pre><p>We initialize the IMU in the user_empty_peripheral_template.c file.</p><pre>void imu_init(void) {<br>  uint8_t raw_data_buffer[14] = {0};</pre><pre>uint8_t I2C_Response = 0xFF;<br>  lsm6ds3_int1_route_t int_1_reg;<br>  uint8_t who_am_i = 0;</pre><pre>while (who_am_i != LSM6DS3_ID) {<br>    lsm6ds3_device_id_get( &amp;dev_ctx, &amp;who_am_i);<br>  }<br>  /* Reset IMU */<br>  lsm6ds3_reset_set( &amp;dev_ctx, PROPERTY_ENABLE);<br>  do {<br>    lsm6ds3_reset_get( &amp; dev_ctx, &amp;I2C_Response);<br>  }<br>  while (I2C_Response);</pre><pre>/* Enable Block Data Update */<br>  lsm6ds3_block_data_update_set( &amp;dev_ctx, PROPERTY_ENABLE);</pre><pre>/* Set full scale */<br>  lsm6ds3_xl_full_scale_set( &amp;dev_ctx, LSM6DS3_2g);<br>  lsm6ds3_gy_full_scale_set( &amp;dev_ctx, LSM6DS3_2000dps);</pre><pre>/* Set Output Data Rate */<br>  lsm6ds3_xl_data_rate_set( &amp;dev_ctx, LSM6DS3_XL_ODR_12Hz5);<br>  lsm6ds3_gy_data_rate_set( &amp;dev_ctx, LSM6DS3_GY_ODR_12Hz5);</pre><pre>lsm6ds3_xl_power_mode_set( &amp;dev_ctx, LSM6DS3_XL_NORMAL);<br>  lsm6ds3_gy_power_mode_set( &amp;dev_ctx, LSM6DS3_GY_NORMAL);</pre><pre>/* Set Interrupt Pin Active High */<br>  lsm6ds3_pin_polarity_set( &amp;dev_ctx, LSM6DS3_ACTIVE_LOW);</pre><pre>lsm6ds3_int_notification_set( &amp;dev_ctx, LSM6DS3_INT_LATCHED);</pre><pre>/* Set Accelerometer Data-Ready Interrupt */<br>  lsm6ds3_pin_int1_route_get( &amp;dev_ctx, &amp;int_1_reg);<br>  int_1_reg.int1_drdy_xl = PROPERTY_ENABLE;<br>  lsm6ds3_pin_int1_route_set( &amp;dev_ctx, &amp;int_1_reg);</pre><pre>/* Synchronise Interrupt Signal */<br>  lsm6ds3_xl_flag_data_ready_get( &amp;dev_ctx, &amp;I2C_Response);<br>  do {<br>    lsm6ds3_xl_g_raw_get( &amp;dev_ctx, raw_data_buffer);<br>    lsm6ds3_xl_flag_data_ready_get( &amp;dev_ctx, &amp;I2C_Response);<br>  }<br>  while (I2C_Response);<br>}</pre><p>The above function performs the following actions:</p><ul><li>Read the WHO_AM_I register and waits for it to give the correct value.</li><li>Reset the IMU.</li><li>Enables the block data update setting which ensures that the interrupt will be fired only after all the 3 axis data for the accelerometer and gyroscope have been updated in the registers.</li><li>Set the scale, output data rate and the power mode for the Accelerometer and Gyroscope.</li><li>Set the INT1 pin to active high and latched. Latching it ensures that the interrupt line does not go low till the data is read.</li><li>Configure the INT1 pin to be mapped with the Data ready signal.</li></ul><p>The GPIO interrupt is configured in the custom callback <em>user_app_on_init</em>() function. For more details about the custom callback and GPIO interrupt, take a look at my tutorial on <a href="https://medium.com/vicara-hardware-university/dialog-da14531-gpio-buttons-and-leds-39f38804db8a">GPIOs, buttons and LEDs</a>.</p><pre>void user_app_on_init(void)<br>{<br>    imu_init();<br>    GPIO_EnableIRQ(GPIO_PORT_0, GPIO_PIN_7, GPIO0_IRQn, true, false, 0);<br>    GPIO_RegisterCallback(GPIO0_IRQn, interrupt_handler);<br>    default_app_on_init();<br>}</pre><p>The <em>interrupt_handler() </em>is called every time the interrupt is detected. The function also reads the accelerometer and gyroscope data from the LSM6DS3.</p><pre>uint8_t accel_data_buffer[12] = {0};</pre><pre>void interrupt_handler()<br>{<br>    lsm6ds3_xl_g_raw_get(&amp;dev_ctx, accel_data_buffer);<br>    NVIC_ClearPendingIRQ(GPIO0_IRQn);<br>}</pre><h3>Testing</h3><p>Build the project and start the debugger with the DA14531 connected to your computer. If there are any issues with the working of the circuit, the execution of the program will stop. Add the accel_data_buffer variable to the expressions window. Take a look at my <a href="https://medium.com/vicara-hardware-university/dialog-da14531-adc-655c0194ea36">DA14531 ADC tutorial</a> to check how to view the variable values by adding them to the expressions window. Pause and resume the execution multiple times to view the values change.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3b0dc5d9e00" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vicara-hardware-university/dialog-da14531-interrupts-c3b0dc5d9e00">Dialog DA14531 — Interrupts</a> was originally published in <a href="https://medium.com/vicara-hardware-university">Vicara Hardware University</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dialog DA14531 — ADC]]></title>
            <link>https://medium.com/vicara-hardware-university/dialog-da14531-adc-655c0194ea36?source=rss----2078122dd7e9---4</link>
            <guid isPermaLink="false">https://medium.com/p/655c0194ea36</guid>
            <category><![CDATA[bluetooth-low-energy]]></category>
            <category><![CDATA[electronics]]></category>
            <category><![CDATA[microcontrollers]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Gowtham TS]]></dc:creator>
            <pubDate>Tue, 12 Jan 2021 09:14:39 GMT</pubDate>
            <atom:updated>2021-01-12T09:14:29.132Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dialog DA14531 — ADC</h3><p>An <strong>A</strong>nalog to <strong>D</strong>igital <strong>C</strong>onverter transforms an analog signal to a digital form which can be used by/operated upon by any computing element. The analog signal is sampled periodically to recreate it digitally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/0*95tq2gDGzSK-hPk1.png" /></figure><p>The DA14531 has 10 bit ADC with 4input single ended channels(or 2 differential channels). The 4 input channels can be chosen from 4 GPIOs, a temperature sensor, VBAT_HIGH rail, VBAT_LOW rail and VDD. It also has a configurable attenuator with 4 options which are1x, 2x, 3x and 4x. With the attenuator at 4x, it can sample a maximum voltage range of -3.45V to +3.45V .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*0Ne4c7IT3_pKuqMRa7Lmzw.png" /></figure><h3>Project setup</h3><p>The project with the code for this tutorial is available on Github at <a href="https://github.com/vicara-hq/da14531-tutorials">https://github.com/vicara-hq/da14531-tutorials</a></p><p>Download the project and copy it. The project has to be placed inside the Dialog SDK6 folder. Navigate to <em>&lt;SDK6_ROOT&gt;/projects/target_apps/template </em>and paste it in this folder. The project is a modified version of the <em>empty_peripheral_template </em>project provided by Dialog. But to keep this tutorial series as open source as possible, all the following steps will use the SmartSnippets Studio.</p><h3>Hardware overview</h3><p>We will use a DA145xx Pro motherboard with a DA14531 Tiny module daughterboard, few jumpers and a breadboard. You will also need 2 resistors of equal value or you can also use a potentiometer(you will need a multimeter to verify the output).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*5qh-EYgNP3Zi4cz4E7dqPA.png" /></figure><p>I used 2 4.7 kOhm resistors and 3V rail on the DA14531 motherboard as VCC.</p><h3>Code Overview</h3><p>The aim of this tutorial is to sample a voltage and show the basic usage of the ADC in the DA14531.</p><p>First, we need to configure P0_7 as an ADC pin. This is done in the user_periph_setup.c file.</p><pre>void GPIO_reservations(void) {<br>  RESERVE_GPIO(BUTTON, GPIO_PORT_0, GPIO_PIN_7, PID_ADC);<br>}</pre><pre>void set_pad_functions(void) {<br>  GPIO_ConfigurePin(GPIO_PORT_0, GPIO_PIN_7, INPUT, PID_ADC, false);<br>}</pre><p>The below block of code configures the ADC.</p><pre>adc_config_t adc_cfg = {<br>  .input_mode = ADC_INPUT_MODE_SINGLE_ENDED,<br>  .input = ADC_INPUT_SE_P0_7,<br>  .smpl_time_mult = 2,<br>  .continuous = false,<br>  .interval_mult = 0,<br>  .input_attenuator = ADC_INPUT_ATTN_2X,<br>  .chopping = false,<br>  .oversampling = 0<br>};</pre><pre>adc_offset_calibrate(ADC_INPUT_MODE_SINGLE_ENDED);</pre><pre>adc_init( &amp;adc_cfg);</pre><p>In the configuration structure, we set the mode to single ended and the attenuation to 2x as the expected voltage is around 1.5V . The function to also calibrate the ADC is called before initializing it.</p><p>We call the function to sample the voltage in the custom <em>app_on_init </em>callback. For more details about the custom callback, take a look at my tutorial on <a href="https://medium.com/vicara-hardware-university/dialog-da14531-gpio-buttons-and-leds-39f38804db8a">GPIOs, buttons and LEDs</a>.</p><pre>uint16_t adc_sample;</pre><pre>void user_app_on_init(void) {<br>  adc_sample = adc_get_sample();<br>  adc_sample = adc_correct_sample(adc_sample);</pre><pre>  default_app_on_init();<br>}</pre><h3>Testing</h3><p>The easiest way to test this is to run the debugger and add the variable <em>adc_sample </em>to the Expressions watch window. To add a variable to the Expressions watch window and to check it’s value:</p><ul><li>Select the variable</li><li>Right click on it and choose “Add watch expression”.</li><li>Click on “OK” in the window which opens up</li><li>Pause the debugger after few seconds and check the value of the variable.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*LH0otjB84bT-rue2IekCWg.png" /></figure><p>The value I got was 0x3A0. The reference voltage of the ADC is 0.9V and since it’s a 10 bit ADC, the value corresponds to:</p><pre>0x3A0 = 928 (in decimal)</pre><pre>2 * 928 * (0.9/1024) = 1.63V </pre><p>The value I got is a bit higher than expected. This error can be reduced by using techniques like oversampling but that’s an advanced topic for another tutorial.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=655c0194ea36" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vicara-hardware-university/dialog-da14531-adc-655c0194ea36">Dialog DA14531 — ADC</a> was originally published in <a href="https://medium.com/vicara-hardware-university">Vicara Hardware University</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dialog DA14531 — SPI]]></title>
            <link>https://medium.com/vicara-hardware-university/dialog-da14531-spi-d5b34fd3cc5b?source=rss----2078122dd7e9---4</link>
            <guid isPermaLink="false">https://medium.com/p/d5b34fd3cc5b</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[microcontrollers]]></category>
            <category><![CDATA[electronics]]></category>
            <category><![CDATA[bluetooth-low-energy]]></category>
            <dc:creator><![CDATA[Gowtham TS]]></dc:creator>
            <pubDate>Tue, 12 Jan 2021 09:03:31 GMT</pubDate>
            <atom:updated>2021-01-12T09:03:16.258Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dialog DA14531 — SPI</h3><p><strong>S</strong>erial <strong>P</strong>eripheral <strong>I</strong>nterface (SPI) is a synchronous serial communication interface specification used for short-distance communication, primarily in embedded systems. The interface was developed by Motorola in the mid-1980s and has become a de facto standard.</p><p>SPI is a full duplex protocol which uses 4 pins. One might think that I2C seems like a better protocol as it uses only 2 pins but SPI has a higher clock frequency than I2C. It also uses Push Pull to control the lines rather than an Open collector system, which removes the need for pull up resistors.</p><p>SPI can be thought of as 2 shift registers which are connected by wires.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*OjAPm1D44G14cEsA.png" /></figure><p>The DA14531 supports the following parameters for SPI:</p><ul><li>Master and Slave mode</li><li>4 bit to 32 bit operation</li><li>Master clock line upto 32 MHz, Slave clock line upto 16 MHz</li><li>1 byte x 4 byte individual FIFO s for RX and TX</li><li>Blocking, Interrupt and DMA modes</li></ul><h3>Project setup</h3><p>The project with the code for this tutorial is available on Github at <a href="https://github.com/vicara-hq/da14531-tutorials">https://github.com/vicara-hq/da14531-tutorials</a></p><p>Download the project and copy it. The project has to be placed inside the Dialog SDK6 folder. Navigate to <em>&lt;SDK6_ROOT&gt;/projects/target_apps/template </em>and paste it in this folder. The project is a modified version of the <em>empty_peripheral_template </em>project provided by Dialog. But to keep this tutorial series as open source as possible, all the following steps will use the SmartSnippets Studio.</p><h3>Hardware overview</h3><p>We will use a DA145xx Pro motherboard with a DA14531 Tiny module daughterboard with a STEVAL-MKI160V1. The STEVAL-MKI160V1 is an evaluation kit for the LSM6DS3, which is a 6-axis IMU. Other than this, we will also need a few jumpers and a breadboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-XZa3vOMKAcCPvAJJFzsjw.png" /></figure><blockquote>Note: VCC in the circuit refers to 3V</blockquote><h3>Code Overview</h3><p>The aim of this tutorial is to use SPI to read the WHO_AM_I register and reset the IMU.</p><p>You can take a look at my blog on the <a href="https://medium.com/vicara-hardware-university/dialog-da14531-i2c-c2f6d12d0a8d">I2C peripheral on the DA14531</a> as I have used the LSM6DS3 in it.</p><p>First, we need to configure the pins to be used for SPI in the user_periph_setup.c file. I would suggest that you use the same pins as mentioned in the below code as other pins are connected to other components like buttons, LEDs on the daughterboard.</p><pre>void GPIO_reservations(void) {<br>  RESERVE_GPIO(SDA, GPIO_PORT_0, GPIO_PIN_11, PID_SPI_DO);<br>  RESERVE_GPIO(SCL, GPIO_PORT_0, GPIO_PIN_6, PID_SPI_DI);<br>  RESERVE_GPIO(SCL, GPIO_PORT_0, GPIO_PIN_8, PID_SPI_CLK);<br>  RESERVE_GPIO(SCL, GPIO_PORT_0, GPIO_PIN_7, PID_SPI_EN);<br>}</pre><pre>void set_pad_functions(void) {<br>  GPIO_ConfigurePin(GPIO_PORT_0, GPIO_PIN_11, OUTPUT, PID_SPI_DO, true);<br>  GPIO_ConfigurePin(GPIO_PORT_0, GPIO_PIN_6, INPUT, PID_SPI_DI, true);<br>  GPIO_ConfigurePin(GPIO_PORT_0, GPIO_PIN_8, OUTPUT, PID_SPI_CLK, true);<br>  GPIO_ConfigurePin(GPIO_PORT_0, GPIO_PIN_7, OUTPUT, PID_SPI_EN, true);<br>}</pre><p>Next, in the <em>periph_init()</em> function, we need to initialize the SPI peripheral.</p><pre>// Configuration struct for SPI<br>static const spi_cfg_t spi_cfg = {<br>  .spi_ms = SPI_MS_MODE_MASTER,<br>  .spi_cp = SPI_CP_MODE_0,<br>  .spi_speed = SPI_SPEED_MODE_2MHz,<br>  .spi_wsz = SPI_MODE_8BIT,<br>  .spi_cs = SPI_CS_0,<br>  .cs_pad.port = GPIO_PORT_0,<br>  .cs_pad.pin = GPIO_PIN_7,<br>  #if defined(CFG_SPI_DMA_SUPPORT)<br>  .spi_dma_channel = SPI_DMA_CHANNEL_01,<br>  .spi_dma_priority = DMA_PRIO_0,<br>  #endif<br>};</pre><pre>spi_initialize(&amp;spi_cfg);</pre><p>The above structure configures the SPI peripheral in Master mode with a clock frequency of 2 MHz, word size of 8 bits and Mode 0. SPI has 4 modes which decide when the signal lines need to be sampled. In the DA14531, the SPI Peripheral provides the option to use 2 CS(Chip Select) lines or to use any GPIO as a CS line or to not use a CS line.</p><p>In the user_empty_peripheral_template.c, we will add a <em>read_who_am_i_reg()</em> function which has a different implementation when compared to it’s I2C counterpart.</p><pre>void read_who_am_i_reg() {<br>  uint8_t reg_val = 0;<br>  while (reg_val != 0x69) {<br>    uint8_t reg_addr = 0x80 | 0x0F;<br>    spi_cs_low();<br>    spi_send( &amp; reg_addr, 1, SPI_OP_BLOCKING);<br>    spi_receive( &amp; reg_val, 1, SPI_OP_BLOCKING);<br>    spi_cs_high();<br>  }<br>}</pre><p>As done in my DA14531 I2C blog, the <em>read_who_am_i_reg() </em>is called in the <em>user_app_on_init() </em>function.</p><pre>void user_app_on_init(void) {<br>  read_who_am_i_reg();<br>  default_app_on_init();<br>}</pre><h3>Testing</h3><p>Build the project and start the debugger with the DA14531 connected to your computer. If there are any issues with the working of the circuit, the execution of the program will stop. You can also place a breakpoint in the <em>read_who_am_i_reg() </em>function and step through it to view the value read from the LSM6DS3.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5b34fd3cc5b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vicara-hardware-university/dialog-da14531-spi-d5b34fd3cc5b">Dialog DA14531 — SPI</a> was originally published in <a href="https://medium.com/vicara-hardware-university">Vicara Hardware University</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[STM32 Guide: Interrupts]]></title>
            <link>https://medium.com/vicara-hardware-university/stm32-guide-interrupts-c8552be62164?source=rss----2078122dd7e9---4</link>
            <guid isPermaLink="false">https://medium.com/p/c8552be62164</guid>
            <category><![CDATA[microcontrollers]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[electronics]]></category>
            <category><![CDATA[stm32]]></category>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Sanskar Biswal]]></dc:creator>
            <pubDate>Tue, 12 Jan 2021 05:28:05 GMT</pubDate>
            <atom:updated>2021-01-04T14:36:55.182Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*uGd6RWitXkhNyvq03EMmeA.png" /><figcaption>Fig.1 STM32 F4 Dev Kit</figcaption></figure><h3>Prerequisites:</h3><p>This is tutorial is not intended to be a guide for learning C language or about the STM32 platform. It’s primary target is to provide developers a concise guide about integrating peripheral modules and features into active applications.</p><p>If you are a beginner, I would recommend you look into an STM32 Project Setup guide like this one.</p><blockquote><a href="https://medium.com/vicara-hardware-university/smt32-project-setup-with-cubeide-947974baf713"><em>https://medium.com/vicara-hardware-university/smt32-project-setup-with-cubeide-947974baf713</em></a></blockquote><h3>Interrupts</h3><p>Interrupts in microcontroller are inputs for external sources or internal processes, which when triggered can stop the currently executing task and run a different sequence of tasks.</p><p>The applications range from making real-time response systems to reducing power consumption and it is used in a wide variety of embedded systems.</p><p>Interrupts are essentially signals and can arrive at the GPIO pin in one of the following 3 methods</p><ul><li>Rising Edge</li><li>Falling Edge</li><li>Toggle (Rising and Falling)</li></ul><h3>EXTI in STM32</h3><p>STM32F4 has 7 interrupts</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*40pL7Js3DQhEug_h9iDFyg.png" /><figcaption>Fig.2 Table of EXTI Mapping</figcaption></figure><h4>Setting Up Interrupt Handler</h4><pre><strong><em>void</em></strong> EXTI0_IRQHandler(<strong><em>void</em></strong>) {<br>   /* Make sure that interrupt flag is set */<br>   <strong><em>if</em></strong> (EXTI_GetITStatus(EXTI_Line0) != RESET) {<br>      /* Do your stuff when EXTI0 is changed */</pre><pre>      /* Clear interrupt flag */<br>      EXTI_ClearITPendingBit(EXTI_Line0)}</pre><pre>   }<br>   /* Handle IRQ10-15 interrupt */<br>   <strong><em>void</em></strong> EXTI15_10_IRQHandler(<strong><em>void</em></strong>) {<br>      /* Make sure that interrupt flag is set */<br>      <strong><em>if</em></strong> (EXTI_GetITStatus(EXTI_Line12) != RESET) {<br>      /* Do your stuff when EXTI is changed */<br>      <br>      /* Clear interrupt flag */<br>      EXTI_ClearITPendingBit(EXTI_Line12);<br>   }<br>}</pre><h3>Conclusion</h3><p>In this tutorial, we discussed the methods for using External Interrupts (EXTI)</p><h3>Sources:</h3><ul><li>Fig.1: <a href="https://microcontrollerslab.com/stm32f4-discovery-board-pinout-features-examples/">https://microcontrollerslab.com/stm32f4-discovery-board-pinout-features-examples/</a></li><li>HAL Documentation: <a href="https://www.st.com/resource/en/user_manual/dm00105879-description-of-stm32f4-hal-and-ll-drivers-stmicroelectronics.pdf">https://www.st.com/resource/en/user_manual/dm00105879-description-of-stm32f4-hal-and-ll-drivers-stmicroelectronics.pdf</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8552be62164" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vicara-hardware-university/stm32-guide-interrupts-c8552be62164">STM32 Guide: Interrupts</a> was originally published in <a href="https://medium.com/vicara-hardware-university">Vicara Hardware University</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>