<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Search Results for &#8220;bootloader&#8221; &#8211; IoT Expert</title>
	<atom:link href="https://iotexpert.com/search/bootloader/feed/rss2/" rel="self" type="application/rss+xml" />
	<link>https://iotexpert.com</link>
	<description>Engineering for the Internet of Things</description>
	<lastBuildDate>Sun, 30 Jun 2019 21:47:06 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://iotexpert.com/wp-content/uploads/2017/01/cropped-Avatar-32x32.jpg</url>
	<title>Search Results for &#8220;bootloader&#8221; &#8211; IoT Expert</title>
	<link>https://iotexpert.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Repair the Elkhorn Creek Water Level Sensor</title>
		<link>https://iotexpert.com/repair-the-elkhorn-creek-water-level-sensor/</link>
					<comments>https://iotexpert.com/repair-the-elkhorn-creek-water-level-sensor/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Mon, 01 Jul 2019 12:00:28 +0000</pubDate>
				<category><![CDATA[Elkhorn Creek]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=7314</guid>

					<description><![CDATA[Summary As many of you have noticed, www.elkhorn-creek.org has been offline for quite a while (actually since December 22,2018).  I know that many of you have really missed knowing how much water is in the creek.  Given that it blew up in December, and I knew that I was going to have to crawl into [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>Summary</h1>
<p>As many of you have noticed, <a href="http://www.elkhorn-creek.org" target="_blank" rel="noopener noreferrer">www.elkhorn-creek.org</a> has been offline for quite a while (actually since December 22,2018).  I know that many of you have really missed knowing how much water is in the creek.  Given that it blew up in December, and I knew that I was going to have to crawl into the muddy creek to fix it, I had not gotten around to it.  But, now it is July and the water is nice, so I don&#8217;t have much of an excuse.  I have <a href="https://iotexpert.com/category/solutions/elkhorn-creek/" target="_blank" rel="noopener noreferrer">written</a> extensively about my system, in fact, it was my first real IoT project.  I assumed that it would not be that hard to fix.  Boy was I wrong.</p>
<p>In this article I will:</p>
<ul>
<li>Get the Sensor out of the Elkhorn Creek &amp; Debug</li>
<li>Update the PSoC Project to use a Different GPIO</li>
<li>Blow up the CyPi Power Supply</li>
<li>Debug the Wrong Pressure Sensor</li>
<li>Turn the Raspberry Pi Back on and Retest</li>
</ul>
<h1>Get the Sensor out of the Creek and Debug</h1>
<p>I felt like Stanley in the Congo heading down the path to the Elkhorn Creek.</p>
<p><a href="https://iotexpert.com/?attachment_id=7344" rel="attachment wp-att-7344"><img fetchpriority="high" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0606-768x1024.jpg" alt="" width="768" height="1024" class="alignnone size-large wp-image-7344" srcset="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0606-768x1024.jpg 768w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0606-600x800.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0606-225x300.jpg 225w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0606-scaled.jpg 1920w" sizes="(max-width: 768px) 100vw, 768px" /></a></p>
<p>But, when you get there, look how beautiful it is.</p>
<p><a href="https://iotexpert.com/?attachment_id=7343" rel="attachment wp-att-7343"><img decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0607-768x1024.jpg" alt="" width="768" height="1024" class="alignnone size-large wp-image-7343" srcset="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0607-768x1024.jpg 768w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0607-600x800.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0607-225x300.jpg 225w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0607-scaled.jpg 1920w" sizes="(max-width: 768px) 100vw, 768px" /></a></p>
<p>Here is a picture looking down at the sensor setup from the top of the bank (that is a 6 foot ladder, so that bank is something like 10 feet high)</p>
<p><a href="https://iotexpert.com/?attachment_id=7342" rel="attachment wp-att-7342"><img decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0609-768x1024.jpg" alt="" width="768" height="1024" class="alignnone size-large wp-image-7342" srcset="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0609-768x1024.jpg 768w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0609-600x800.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0609-225x300.jpg 225w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0609-scaled.jpg 1920w" sizes="(max-width: 768px) 100vw, 768px" /></a></p>
<p>When you slide down the bank onto the ladder, this is where you end up.  After I jumped off the ladder into the creek, I was in mud up to my knees.  I had assumed that the problem was that water had leaked around sensor NPT connection.  You can see the drain valve that I installed to drain water out of the pipe for just that case.  When I opened the valve, there was no water&#8230; like none. This made me start to wonder what was going on.  The sensor is installed in the end of that square clear out.</p>
<p><a href="https://iotexpert.com/?attachment_id=7343" rel="attachment wp-att-7343"></a><a href="https://iotexpert.com/?attachment_id=7341" rel="attachment wp-att-7341"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0610-768x1024.jpg" alt="" width="768" height="1024" class="alignnone size-large wp-image-7341" srcset="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0610-768x1024.jpg 768w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0610-600x800.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0610-225x300.jpg 225w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0610-scaled.jpg 1920w" sizes="(max-width: 768px) 100vw, 768px" /></a><a href="https://iotexpert.com/?attachment_id=7343" rel="attachment wp-att-7343"></a></p>
<p>When I undid the sensor and brought it up into my lab, there was no leaking around the sensor.  My original theory that the sensor had gotten water onto the dry side was incorrect.</p>
<p><a href="https://iotexpert.com/?attachment_id=7332" rel="attachment wp-att-7332"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0596-768x1024.jpg" alt="" width="768" height="1024" class="alignnone size-large wp-image-7332" srcset="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0596-768x1024.jpg 768w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0596-600x800.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0596-225x300.jpg 225w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0596-scaled.jpg 1920w" sizes="(max-width: 768px) 100vw, 768px" /></a></p>
<p>So, I plugged the sensor in on my bench to try to figure out what was going on.</p>
<p><a href="https://iotexpert.com/?attachment_id=7331" rel="attachment wp-att-7331"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0594-768x1024.jpg" alt="" width="768" height="1024" class="alignnone size-large wp-image-7331" srcset="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0594-768x1024.jpg 768w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0594-600x800.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0594-225x300.jpg 225w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0594-scaled.jpg 1920w" sizes="(max-width: 768px) 100vw, 768px" /></a></p>
<p>The first measurement I took was across the 51.1 ohm sensor resistor.  Last time I checked, V=IR, so this means that it is drawing 133mA.  That is bad given that it is a 4-20mA current loop.</p>
<p><a href="https://iotexpert.com/?attachment_id=7333" rel="attachment wp-att-7333"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0598-768x1024.jpg" alt="" width="768" height="1024" class="alignnone size-large wp-image-7333" srcset="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0598-768x1024.jpg 768w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0598-600x800.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0598-225x300.jpg 225w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0598-scaled.jpg 1920w" sizes="(max-width: 768px) 100vw, 768px" /></a></p>
<p>It is also bad to put 6.81V onto a PSoC pin.  When I measure the voltage at the pin it is 0.003 V.  Dead.  At this point, I suspect that whatever killed the sensor also killed the PSoC, but I don&#8217;t know.  I suppose that the sensor could have blown up (maybe an ESD event) and then when the voltage went to 6.81, it blew up the PSoC?  I suppose that I will never know.</p>
<p><a href="https://iotexpert.com/?attachment_id=7334" rel="attachment wp-att-7334"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0599-768x1024.jpg" alt="" width="768" height="1024" class="alignnone size-large wp-image-7334" srcset="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0599-768x1024.jpg 768w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0599-600x800.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0599-225x300.jpg 225w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0599-scaled.jpg 1920w" sizes="(max-width: 768px) 100vw, 768px" /></a></p>
<p>In fact, when I connect the power supply directly to the A0/P2[0] analog input, I get 0.023A &#8230; which means that I also blew up the GPIO and it is now shorted to ground.  Well, actually it isn&#8217;t a short, it is more like 43 Ohm resistor.  Bad.</p>
<p><a href="https://iotexpert.com/?attachment_id=7330" rel="attachment wp-att-7330"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0593-768x1024.jpg" alt="" width="768" height="1024" class="alignnone size-large wp-image-7330" srcset="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0593-768x1024.jpg 768w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0593-600x800.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0593-225x300.jpg 225w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0593-scaled.jpg 1920w" sizes="(max-width: 768px) 100vw, 768px" /></a></p>
<p>Here is the spec from the PSoC 4 data sheet.  2mA is a long long way from 2nA.</p>
<p><a href="https://iotexpert.com/?attachment_id=7353" rel="attachment wp-att-7353"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-4.52.05-PM-1024x54.png" alt="" width="1024" height="54" class="alignnone size-large wp-image-7353" srcset="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-4.52.05-PM-1024x54.png 1024w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-4.52.05-PM-600x31.png 600w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-4.52.05-PM-300x16.png 300w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-4.52.05-PM-768x40.png 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Unfortunately, this is the only CyPi board that I have.  Moreover, I don&#8217;t have another PSoC4 chip to fix it with (or at least at my house right now).  So, I decided that I will assume that the other pins are OK and I will use PSoC Creator to move to another pin (A2) that hopefully isn&#8217;t blown up.  To do this, I snip off the Arduino pin, then solder a jumper on the top from A0 to A2.</p>
<p><a href="https://iotexpert.com/?attachment_id=7346" rel="attachment wp-att-7346"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0601-768x1024.jpg" alt="" width="768" height="1024" class="alignnone size-large wp-image-7346" srcset="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0601-768x1024.jpg 768w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0601-600x800.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0601-225x300.jpg 225w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0601-scaled.jpg 1920w" sizes="(max-width: 768px) 100vw, 768px" /></a></p>
<h1>Update the PSoC Project to use a Different GPIO</h1>
<p>Next, I have to fix the firmware to use A2 instead of A0.  This is AKA P2[2] instead of P2[0].  When I open up the workspace in PSoC Creator, it immediately starts complaining about components that are old.  Notice that all of the &#8220;dwr&#8217;s&#8221; which are opened have an asterisk indicating they have changed.  In order to fix this I need to update all of the components.</p>
<p><a href="https://iotexpert.com/?attachment_id=7315" rel="attachment wp-att-7315"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.25.56-AM-1024x707.png" alt="" width="1024" height="707" class="alignnone size-large wp-image-7315" srcset="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.25.56-AM-1024x707.png 1024w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.25.56-AM-600x414.png 600w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.25.56-AM-300x207.png 300w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.25.56-AM-768x530.png 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Starting with the boot loader project called &#8220;p4bootloader&#8221;, right click and select &#8220;Update Components&#8230;&#8221;</p>
<p><a href="https://iotexpert.com/?attachment_id=7316" rel="attachment wp-att-7316"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.27.04-AM.png" alt="" width="790" height="416" class="alignnone size-full wp-image-7316" srcset="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.27.04-AM.png 790w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.27.04-AM-600x316.png 600w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.27.04-AM-300x158.png 300w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.27.04-AM-768x404.png 768w" sizes="(max-width: 790px) 100vw, 790px" /></a></p>
<p>Notice that eight of the components in the project are old.  Select Next.</p>
<p><a href="https://iotexpert.com/?attachment_id=7317" rel="attachment wp-att-7317"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.27.38-AM-1024x710.png" alt="" width="1024" height="710" class="alignnone size-large wp-image-7317" srcset="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.27.38-AM-1024x710.png 1024w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.27.38-AM-600x416.png 600w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.27.38-AM-300x208.png 300w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.27.38-AM-768x532.png 768w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.27.38-AM.png 1296w" sizes="(max-width: 1024px) 100vw, 1024px" /></a> <a href="https://iotexpert.com/?attachment_id=7318" rel="attachment wp-att-7318"></a></p>
<p>Then turn off the &#8220;create a workspace archive before updating option&#8221;.  My project is in Git so I don&#8217;t need to save it in case something bad happens.  Then click Finish.</p>
<p><a href="https://iotexpert.com/?attachment_id=7318" rel="attachment wp-att-7318"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.28.00-AM-1024x710.png" alt="" width="1024" height="710" class="alignnone size-large wp-image-7318" srcset="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.28.00-AM-1024x710.png 1024w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.28.00-AM-600x416.png 600w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.28.00-AM-300x208.png 300w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.28.00-AM-768x532.png 768w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.28.00-AM.png 1290w" sizes="(max-width: 1024px) 100vw, 1024px" /></a> <a href="https://iotexpert.com/?attachment_id=7319" rel="attachment wp-att-7319"></a></p>
<p>And after a minute I can Build the project.</p>
<p><a href="https://iotexpert.com/?attachment_id=7319" rel="attachment wp-att-7319"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.28.19-AM.png" alt="" width="896" height="200" class="alignnone size-large wp-image-7319" srcset="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.28.19-AM.png 896w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.28.19-AM-600x134.png 600w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.28.19-AM-300x67.png 300w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.28.19-AM-768x171.png 768w" sizes="(max-width: 896px) 100vw, 896px" /></a></p>
<p>Next I update the main project which is called &#8220;p4arduino-creek&#8221;</p>
<p><a href="https://iotexpert.com/?attachment_id=7320" rel="attachment wp-att-7320"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.30.33-AM.png" alt="" width="852" height="334" class="alignnone size-full wp-image-7320" srcset="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.30.33-AM.png 852w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.30.33-AM-600x235.png 600w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.30.33-AM-300x118.png 300w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.30.33-AM-768x301.png 768w" sizes="(max-width: 852px) 100vw, 852px" /></a></p>
<p>Follow the same process as before:</p>
<p><a href="https://iotexpert.com/?attachment_id=7321" rel="attachment wp-att-7321"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.30.56-AM-1024x999.png" alt="" width="1024" height="999" class="alignnone size-large wp-image-7321" srcset="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.30.56-AM-1024x999.png 1024w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.30.56-AM-600x586.png 600w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.30.56-AM-300x293.png 300w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.30.56-AM-768x750.png 768w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.30.56-AM.png 1248w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>In this case I forget to click the archive button, but I can cancel the archive.</p>
<p><a href="https://iotexpert.com/?attachment_id=7322" rel="attachment wp-att-7322"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.31.04-AM-1024x999.png" alt="" width="1024" height="999" class="alignnone size-large wp-image-7322" srcset="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.31.04-AM-1024x999.png 1024w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.31.04-AM-600x586.png 600w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.31.04-AM-300x293.png 300w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.31.04-AM-768x750.png 768w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.31.04-AM.png 1250w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Once the update is done, look at the schematic.  The first thing that I notice is that I called the pressure input &#8220;high side&#8221;.  I hate the name high side&#8230; so I am going to fix it to be called pressure</p>
<p><a href="https://iotexpert.com/?attachment_id=7323" rel="attachment wp-att-7323"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.31.45-AM.png" alt="" width="716" height="556" class="alignnone size-large wp-image-7323" srcset="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.31.45-AM.png 716w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.31.45-AM-600x466.png 600w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.31.45-AM-300x233.png 300w" sizes="(max-width: 716px) 100vw, 716px" /></a></p>
<p>Double click the pin and change it to &#8220;pressure&#8221;</p>
<p><a href="https://iotexpert.com/?attachment_id=7324" rel="attachment wp-att-7324"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.32.04-AM-1024x781.png" alt="" width="1024" height="781" class="alignnone size-large wp-image-7324" srcset="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.32.04-AM-1024x781.png 1024w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.32.04-AM-600x458.png 600w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.32.04-AM-300x229.png 300w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.32.04-AM-768x586.png 768w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.32.04-AM.png 1258w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Because the boot loader hex changed, I need to update the reference in the bootloadable component.  Double click it and correct the path.</p>
<p><a href="https://iotexpert.com/?attachment_id=7325" rel="attachment wp-att-7325"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.39.02-AM-1024x785.png" alt="" width="1024" height="785" class="alignnone size-large wp-image-7325" srcset="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.39.02-AM-1024x785.png 1024w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.39.02-AM-600x460.png 600w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.39.02-AM-300x230.png 300w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.39.02-AM-768x589.png 768w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.39.02-AM.png 1260w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Notice that it has a new version of the compiler.</p>
<p><a href="https://iotexpert.com/?attachment_id=7326" rel="attachment wp-att-7326"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.39.17-AM-1024x748.png" alt="" width="1024" height="748" class="alignnone size-large wp-image-7326" srcset="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.39.17-AM-1024x748.png 1024w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.39.17-AM-600x439.png 600w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.39.17-AM-300x219.png 300w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.39.17-AM-768x561.png 768w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.39.17-AM.png 1836w" sizes="(max-width: 1024px) 100vw, 1024px" /></a> <a href="https://iotexpert.com/?attachment_id=7327" rel="attachment wp-att-7327"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.39.33-AM.png" alt="" width="16" height="164" class="alignnone size-large wp-image-7327" /></a></p>
<p>Then reassign the pressure pin to be P2[2] which is also known as A2</p>
<p><a href="https://iotexpert.com/?attachment_id=7328" rel="attachment wp-att-7328"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.39.43-AM-1024x398.png" alt="" width="1024" height="398" class="alignnone size-large wp-image-7328" srcset="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.39.43-AM-1024x398.png 1024w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.39.43-AM-600x233.png 600w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.39.43-AM-300x117.png 300w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.39.43-AM-768x299.png 768w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.39.43-AM.png 1394w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Then rebuild and notice that everything is OK.</p>
<p><a href="https://iotexpert.com/?attachment_id=7329" rel="attachment wp-att-7329"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.40.53-AM-1024x221.png" alt="" width="1024" height="221" class="alignnone size-large wp-image-7329" srcset="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.40.53-AM-1024x221.png 1024w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.40.53-AM-600x130.png 600w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.40.53-AM-300x65.png 300w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-6.40.53-AM-768x166.png 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Once I reprogram the board, I take it outside to reinstall the whole mess.  After I hook it up I start probing with the multimeter and immediately short out the power supply with one of the multi-meter probes.</p>
<h1>Blow up the CyPi Power Supply</h1>
<p>Which blows up the REG1117.  Here is an animated GIF where you can see that it turns on.. then immediately goes off.  This is more than a little bit annoying.</p>
<p><a href="https://iotexpert.com/?attachment_id=7339" rel="attachment wp-att-7339"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/blownpower.gif" alt="" width="600" height="338" class="alignnone size-full wp-image-7339" /></a></p>
<p>Fortunately, I have my original CyPi prototype.  So, I go back to the prototype CyPi &#8211; which means that I have to use two power supply connections.  One of the things that I fixed in the final CyPI was to have the ability to drive the Raspberry Pi with the 12V input (I have ordered a new REG 1117).</p>
<h1>Debug the Wrong Pressure Sensor</h1>
<p>When I install everything, an unbelievably frustrating thing happens. I put the probe on the sensor and I immediately measure 1.007V  which is 19.7 mA which is also known as 14.7346 PSI.  This is seriously bad.  I have been standing in mud up to my knees fixing the damn system and it is already broken again.  I should be measure 4mA*51.ohm = .202V.  But no.  This was a deeply frustrating moment because I assumed that something else is wrong with my system.</p>
<p>When I got back inside and tried to figure out what in the world was happening, I thought, maybe the pressure sensor is clogged or something?  This made me wonder what the air pressure in Kentucky at that moment was.  After a little bit of google I find that the air pressure is 30 inches of Hg&#8230; which turns out to be &#8230; guess&#8230; 14.7 PSI.  I knew immediately that I purchased the WRONG DAMN SENSOR.</p>
<p>Measurement Specialties makes the US381 in both Gauge and Absolute pressure.  In the Absolute case, it gives you the pressure with a reference to a vacuum.  In the gauge case it gives you a relative measurement.  The back side of this pressure sensor is exposed to the air, which lets it cancel out atmospheric pressure changes.  But I bought US381-000005-015PA instead of the correct US381-000005-015PG.</p>
<p><a href="https://iotexpert.com/?attachment_id=7351" rel="attachment wp-att-7351"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0626-1024x444.jpg" alt="" width="1024" height="444" class="alignnone size-large wp-image-7351" srcset="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0626-1024x444.jpg 1024w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0626-600x260.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0626-300x130.jpg 300w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0626-768x333.jpg 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><br />
And, a few days later Mouser delivered me the correct sensor, and after and hour of mud and sweat I had things ready to try again.</p>
<h1>Turn the Raspberry Pi Back on and Retest</h1>
<p>After re-installing everything in the barn, I now get .202V across the 51.1 Ohm Sensor Resistor, which means that I am getting exactly 4mA.  That makes perfect sense as right now the pressure sensor is just exposed to the air. (meaning it is sticking out of the water)</p>
<p><a href="https://iotexpert.com/?attachment_id=7337" rel="attachment wp-att-7337"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0604-1024x768.jpg" alt="" width="1024" height="768" class="alignnone size-large wp-image-7337" srcset="https://iotexpert.com/wp-content/uploads/2019/06/IMG_0604-1024x768.jpg 1024w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0604-600x450.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0604-300x225.jpg 300w, https://iotexpert.com/wp-content/uploads/2019/06/IMG_0604-768x576.jpg 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>And now <a href="http://www.elkhorn-creek.org" target="_blank" rel="noopener noreferrer">www.elkhorn-creek.org</a> is working again.  Good.</p>
<p><a href="https://iotexpert.com/?attachment_id=7345" rel="attachment wp-att-7345"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-9.25.57-AM-1024x882.png" alt="" width="1024" height="882" class="alignnone size-large wp-image-7345" srcset="https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-9.25.57-AM-1024x882.png 1024w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-9.25.57-AM-600x517.png 600w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-9.25.57-AM-300x258.png 300w, https://iotexpert.com/wp-content/uploads/2019/06/Screen-Shot-2019-06-30-at-9.25.57-AM-768x662.png 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/repair-the-elkhorn-creek-water-level-sensor/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>IoT Mailbox: An Introduction</title>
		<link>https://iotexpert.com/iot-mailbox-an-introduction/</link>
					<comments>https://iotexpert.com/iot-mailbox-an-introduction/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Mon, 13 Aug 2018 12:04:49 +0000</pubDate>
				<category><![CDATA[Bluetooth]]></category>
		<category><![CDATA[WICED]]></category>
		<category><![CDATA[WICED 20719]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=5743</guid>

					<description><![CDATA[Summary On the days that my newspaper carrier decides to deliver the newspaper, you can be sure that it won&#8217;t be there before 4:00am or after 10:00am.  Why do I still get a newspaper?  Because my wife likes it.  The status of the delivery is a constant source of speculation in the morning.  Have you [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>Summary</h1>
<p>On the days that my newspaper carrier decides to deliver the newspaper, you can be sure that it won&#8217;t be there before 4:00am or after 10:00am.  Why do I still get a newspaper?  Because my wife likes it.  The status of the delivery is a constant source of speculation in the morning.  Have you been out to the newspaper box?  Will you go?  etc.  So it seems only logical to make an IoT device that figures out if I have a newspaper.  Obviously this is a bit silly to put as much time and effort as I have into that simple task.  But, doing something cool has it own worth.  And it will give me a chance to use the new WICED XR (extended range) Bluetooth radio module <a href="http://www.cypress.com/documentation/datasheets/cybt-483039-02-ez-bt-xr-wiced-module" target="_blank" rel="noopener">CYBT-483039-02</a>.</p>
<p><a href="https://iotexpert.com/2018/08/13/iot-mailbox-an-introduction/img_6171/" rel="attachment wp-att-5744"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/08/IMG_6171-225x300.jpg" alt="" width="225" height="300" class="alignnone wp-image-5744 size-medium" srcset="https://iotexpert.com/wp-content/uploads/2018/08/IMG_6171-225x300.jpg 225w, https://iotexpert.com/wp-content/uploads/2018/08/IMG_6171-600x800.jpg 600w, https://iotexpert.com/wp-content/uploads/2018/08/IMG_6171-768x1024.jpg 768w, https://iotexpert.com/wp-content/uploads/2018/08/IMG_6171-scaled.jpg 1920w" sizes="(max-width: 225px) 100vw, 225px" /></a></p>
<p>And here is a picture of the new module on the <a href="http://www.cypress.com/documentation/development-kitsboards/cybt-483039-eval-ez-bt-module-arduino-evaluation-board" target="_blank" rel="noopener">CYBT-483039-EVAL EZ-BT</a> evaluation kit.</p>
<p><a href="https://iotexpert.com/2018/08/13/iot-mailbox-an-introduction/cybt-483039-eval/" rel="attachment wp-att-5751"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/08/CYBT-483039-EVAL.jpg" alt="" width="302" height="404" class="alignnone size-full wp-image-5751" srcset="https://iotexpert.com/wp-content/uploads/2018/08/CYBT-483039-EVAL.jpg 302w, https://iotexpert.com/wp-content/uploads/2018/08/CYBT-483039-EVAL-224x300.jpg 224w" sizes="(max-width: 302px) 100vw, 302px" /></a></p>
<p>For this design I want</p>
<ol>
<li>A newspaper sensor (not sure what that will be)</li>
<li>Waterproof case</li>
<li>A temperature sensor</li>
<li>A custom circuit board</li>
<li>A solar battery charger</li>
<li>The ability to program and debug the 20719 (which will be acting as a beacon)</li>
<li>An OTA Bootloader</li>
<li>A Real Time Clock</li>
<li>A wifi/ble bridge (inside the house)</li>
<li>Some cloud data capture and display</li>
<li>An iOS App</li>
</ol>
<p>So far, this project has been quite a rabbit hole as I don&#8217;t/didn&#8217;t know anything about battery power supplies.  Specifically energy harvesting solar powered lithium ion battery chargers and system power supply.  Unfortunately Cypress doesnt make an IC that performs this application &#8230; so if you send Mouser a few hundred dollars and they will send you a box of a bunch of different Solar PMIC Evaluation kits, ST, TI, Linear, Analog Devices, and Microchip. (which I will write about in detail later)</p>
<p><a href="https://iotexpert.com/2018/08/13/iot-mailbox-an-introduction/img_6174/" rel="attachment wp-att-5750"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/08/IMG_6174-e1533994969721-1024x768.jpg" alt="" width="1024" height="768" class="alignnone wp-image-5750 size-large" srcset="https://iotexpert.com/wp-content/uploads/2018/08/IMG_6174-e1533994969721-1024x768.jpg 1024w, https://iotexpert.com/wp-content/uploads/2018/08/IMG_6174-e1533994969721-600x450.jpg 600w, https://iotexpert.com/wp-content/uploads/2018/08/IMG_6174-e1533994969721-300x225.jpg 300w, https://iotexpert.com/wp-content/uploads/2018/08/IMG_6174-e1533994969721-768x576.jpg 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Architecture</h1>
<p>Here is a picture of the architecture.</p>
<p><a href="https://iotexpert.com/2018/08/13/iot-mailbox-an-introduction/mboxarch/" rel="attachment wp-att-5745"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/08/mboxarch-1024x842.png" alt="" width="1024" height="842" class="alignnone size-large wp-image-5745" srcset="https://iotexpert.com/wp-content/uploads/2018/08/mboxarch-1024x842.png 1024w, https://iotexpert.com/wp-content/uploads/2018/08/mboxarch-600x493.png 600w, https://iotexpert.com/wp-content/uploads/2018/08/mboxarch-300x247.png 300w, https://iotexpert.com/wp-content/uploads/2018/08/mboxarch-768x632.png 768w, https://iotexpert.com/wp-content/uploads/2018/08/mboxarch.png 1104w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>In the next Article I will start the process of learning about Solar Battery Charging PMICs.</p>
<p><span><p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >Article</th>
<th >Description</th>
</tr>
</thead>
<tbody>
<tr><td ><a href="https://iotexpert.com/2018/08/13/iot-mailbox-an-introduction/">IoT Mailbox Introduction</a></td>
<td >An introduction to the long series of articles about creating a new IoT System.</td>
</tr>

<tr><td >IoT Mailbox: Solar Battery Chargers &amp; System Power Supplies</td>
<td ></td>
</tr>
</tbody></table></div></p></span></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/iot-mailbox-an-introduction/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Lesson 3 &#8211; WICED Bluetooth: The Super Mux Tool</title>
		<link>https://iotexpert.com/lesson-3-wiced-bluetooth-the-super-mux-tool/</link>
					<comments>https://iotexpert.com/lesson-3-wiced-bluetooth-the-super-mux-tool/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Thu, 28 Jun 2018 12:36:52 +0000</pubDate>
				<category><![CDATA[CYW920179Q40EVB-01]]></category>
		<category><![CDATA[Mouser CYW20719 Bluetooth 5.0]]></category>
		<category><![CDATA[WICED]]></category>
		<category><![CDATA[WICED 20719]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=5402</guid>

					<description><![CDATA[Summary You probably noticed and wondered &#8220;Why did he use WICED_LED_2 instead of WICED_LED_1&#8221;?  The answer to that question is that by default the CYW920719Q40EVB_01 is setup with WICED_LED_2 enabled as a GPIO and WICED_LED_1 used for another purpose.  But to what purpose?  In this lesson we will answer the questions: What are the default [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><span><h1>WICED Bluetooth Using the CYW20719</h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Title</th>
<th >Comment</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/2018/06/23/lesson-0-a-two-hour-wiced-bluetooth-class/">A Two Hour WICED Bluetooth Class</a></td>
<td >WICED Bluetooth Using the CYW20719 in all its glory</td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-1-wiced-bluetooth-a-tour-of-the-resources/">Resources</a></td>
<td ><span>Links to all of the Cypress WICED information including videos, application notes etc.</span></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/">Your First Project</a></td>
<td >Making Hello World &amp; the Blinky LED</td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/">The Super Mux Tool</a></td>
<td >Learning about platforms and the Super Mux Tool</td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-4-wiced-bluetooth-using-snips/">Snips</a></td>
<td >Using the example projects to learn Bluetooth</td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-5-wiced-bluetooth-bluetooth-designer-turn-up-the-radio/">Bluetooth Designer</a></td>
<td >Using the tool to customize a project and get going fast</td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-6-wiced-bluetooth-the-peripheral-comes-alive/">The CCCD &amp; Notification</a></td>
<td >Writing back to the Central</td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-7-wiced-bluetooth-bluetooth-advertising/">Advertising  Beacon</a></td>
<td >Building a beacon project to advertise your custom information </td>
</tr>

<tr><td >8</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-8-wiced-bluetooth-the-advertising-scanner/">Scanner</a></td>
<td >Viewing the world around you</td>
</tr>

<tr><td >9</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-9-wiced-bluetooth-classic-serial-port/">Bluetooth Classic SPP</a></td>
<td >Using the Serial Port Profile to Transmit Lots of Data</td>
</tr>
</tbody></table></div></p>
<p>Source code: </p>
<ul>
<li>git@github.com:iotexpert/wiced_bt_intro.git</li>
<li>https://github.com/iotexpert/wiced_bt_intro</li>
</ul>
<p>&nbsp;</p></span></p>
<h1>Summary</h1>
<p>You probably noticed and wondered &#8220;Why did he use WICED_LED_2 instead of WICED_LED_1&#8221;?  The answer to that question is that by default the CYW920719Q40EVB_01 is setup with WICED_LED_2 enabled as a GPIO and WICED_LED_1 used for another purpose.  But to what purpose?  In this lesson we will answer the questions:</p>
<ol>
<li>What are the default pins?</li>
<li>How do you use the SuperMux tool?</li>
<li>How do you use a PWM?</li>
</ol>
<p>To do this we are going to copy the L2_HelloWorld project and add a PWM to drive the Green LED also known as WICED_LED_1.</p>
<p>The steps we are going to follow are</p>
<ol>
<li>Copy the L2_HelloWorld to start a new project called L3_SuperMux</li>
<li>Rename L2_HelloWorld.c</li>
<li>Fix the makefile.mk for the updated source file</li>
<li>Create a new make target</li>
<li>Program to make sure everything is still working</li>
<li>Look at the platform files for CYW920719Q40EVB_01</li>
<li>Run  the SuperMux Tool</li>
<li>Delete the SPI Slave_1 From the SuperMux</li>
<li>Add an LED to the SuperMux</li>
<li>Configure the LED to P28</li>
<li>Apply the SuperMux configuration</li>
<li>Look at the new files added to the project</li>
<li>Look a the makefile.mk</li>
<li><span>Look L3_SuperMux_pin_config.c</span></li>
<li>Update L3_SuperMux.c to have correct includes</li>
<li>Update L3_SuperMux.c to start the clock, pin and PWM</li>
<li>Program the project</li>
<li>Look at the Hardware Abstraction Layer Documentation</li>
</ol>
<h1>Copy L2_HelloWorld &#8211;&gt; L3_SuperMux</h1>
<p>Instead of starting from a blank project.  Lets make a copy of the L2_HelloWorld project.  If you right click on the L2_HelloWorld folder and select copy</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-00-42-pm/" rel="attachment wp-att-5459"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.00.42-PM.png" alt="" width="382" height="102" class="alignnone size-large wp-image-5459" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.00.42-PM.png 382w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.00.42-PM-300x80.png 300w" sizes="(max-width: 382px) 100vw, 382px" /></a></p>
<p>Then click on the &#8220;wiced_bt_class&#8221; folder and select paste.</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-00-55-pm/" rel="attachment wp-att-5458"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.00.55-PM.png" alt="" width="484" height="103" class="alignnone size-large wp-image-5458" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.00.55-PM.png 484w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.00.55-PM-300x64.png 300w" sizes="(max-width: 484px) 100vw, 484px" /></a></p>
<p>WICED Studio will then complain that you already have a directory called &#8220;L2_HelloWord&#8221; and give you the opportunity to rename it.  Call the new project &#8220;L3_SuperMux&#8221;</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-01-16-pm/" rel="attachment wp-att-5457"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.01.16-PM.png" alt="" width="470" height="166" class="alignnone size-full wp-image-5457" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.01.16-PM.png 470w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.01.16-PM-300x106.png 300w" sizes="(max-width: 470px) 100vw, 470px" /></a></p>
<p>Now you need to rename the L2_HelloWorld.c to be L3_SuperMux.c.  Right click on the L2_HelloWorld.c and select rename</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-02-24-pm/" rel="attachment wp-att-5461"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.02.24-PM.png" alt="" width="391" height="257" class="alignnone size-large wp-image-5461" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.02.24-PM.png 391w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.02.24-PM-300x197.png 300w" sizes="(max-width: 391px) 100vw, 391px" /></a></p>
<p>Then give it a new file name&#8230; like L3_SuperMux.c</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-02-40-pm/" rel="attachment wp-att-5460"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.02.40-PM.png" alt="" width="480" height="158" class="alignnone size-full wp-image-5460" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.02.40-PM.png 480w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.02.40-PM-300x99.png 300w" sizes="(max-width: 480px) 100vw, 480px" /></a></p>
<p>Double click makefile.mk and edit it.  You need to change the comment, and the name of the APP_SRC source file.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#
# Lesson 3 - SuperMux
#
APP_SRC +=  L3_SuperMux.c

C_FLAGS += -DWICED_BT_TRACE_ENABLE
</pre>
<p>Create a make target for this project by right clicking the L2_HelloWorld Make Target, then selecting &#8220;New&#8221;</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-06-23-pm/" rel="attachment wp-att-5464"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.06.23-PM.png" alt="" width="508" height="115" class="alignnone size-large wp-image-5464" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.06.23-PM.png 508w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.06.23-PM-300x68.png 300w" sizes="(max-width: 508px) 100vw, 508px" /></a></p>
<p>That will make a new target&#8230; and it will bring up this dialog box.  Notice that it named the target &#8220;Copy of &#8230;&#8221;</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-06-37-pm/" rel="attachment wp-att-5463"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.06.37-PM.png" alt="" width="635" height="500" class="alignnone size-large wp-image-5463" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.06.37-PM.png 635w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.06.37-PM-600x472.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.06.37-PM-300x236.png 300w" sizes="(max-width: 635px) 100vw, 635px" /></a></p>
<p>Fix it to be &#8220;L3_SuperMux&#8221; like this:</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-06-57-pm/" rel="attachment wp-att-5462"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.06.57-PM.png" alt="" width="634" height="503" class="alignnone size-full wp-image-5462" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.06.57-PM.png 634w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.06.57-PM-600x476.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.06.57-PM-300x238.png 300w" sizes="(max-width: 634px) 100vw, 634px" /></a></p>
<p>You should now have an exact copy of L2_HelloWorld, in the project L3_SuperMux.  Double click the make target and make sure that things are still working.  When you build you should get this.  Don&#8217;t forget to &#8220;Start the Bootloader&#8221; if the programming doesn&#8217;t work.</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-11-48-pm/" rel="attachment wp-att-5465"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.11.48-PM.png" alt="" width="866" height="797" class="alignnone size-full wp-image-5465" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.11.48-PM.png 866w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.11.48-PM-600x552.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.11.48-PM-300x276.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.11.48-PM-768x707.png 768w" sizes="(max-width: 866px) 100vw, 866px" /></a></p>
<h1>Platform Files</h1>
<p>If you look on the back of your CYW920719Q40EVB-01 development kit you will find the exact pin map of this board.  On this picture you can see that LED1 is connected to P28</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/img_5968/" rel="attachment wp-att-5466"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/IMG_5968-768x1024.jpg" alt="" width="768" height="1024" class="alignnone size-large wp-image-5466" srcset="https://iotexpert.com/wp-content/uploads/2018/06/IMG_5968-768x1024.jpg 768w, https://iotexpert.com/wp-content/uploads/2018/06/IMG_5968-600x800.jpg 600w, https://iotexpert.com/wp-content/uploads/2018/06/IMG_5968-225x300.jpg 225w, https://iotexpert.com/wp-content/uploads/2018/06/IMG_5968-scaled.jpg 1920w" sizes="(max-width: 768px) 100vw, 768px" /></a></p>
<p>In WICED Studio, the world &#8220;Platform&#8221; is just another word for Board Support Package.  Basically all of the configuration required to build the firmware for a specific board.  If you click on platforms you will find a directory for the CYW920719Q40EVB.  All of the default configuration for the pins are located in the file &#8220;wiced_platform_pin_config.c&#8221;</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-18-42-pm/" rel="attachment wp-att-5467"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.18.42-PM-1024x444.png" alt="" width="1024" height="444" class="alignnone size-large wp-image-5467" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.18.42-PM-1024x444.png 1024w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.18.42-PM-600x260.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.18.42-PM-300x130.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.18.42-PM-768x333.png 768w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.18.42-PM.png 1243w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>If you look at this file closely, you will see on line 47 that pin P28 is setup as the MOSI of WICED_SPI_1.  That isnt a GPIO!!!.  And you will see a whole block of code on line 74 that is commented out that COULD   configure P28 as a GPIO.  But that would require modifying our default platform files, which I dont want to do.  Now what?  Simple use the SuperMux tool.</p>
<pre class="start-line:33 EnlighterJSRAW" data-enlighter-language="c"">/* all the pins available on this platform and their chosen functionality */
const wiced_platform_gpio_t platform_gpio_pins[] =
    {
        [PLATFORM_GPIO_0 ] = {WICED_P00, WICED_GPIO              },      //Button
        [PLATFORM_GPIO_1 ] = {WICED_P01, WICED_SPI_1_MISO        },
        [PLATFORM_GPIO_2 ] = {WICED_P02, WICED_PCM_OUT_I2S_DO    },
        [PLATFORM_GPIO_3 ] = {WICED_P04, WICED_PCM_IN_I2S_DI     },
        [PLATFORM_GPIO_4 ] = {WICED_P06, WICED_GCI_SECI_IN       },
        [PLATFORM_GPIO_5 ] = {WICED_P07, WICED_SPI_1_CS          },
        [PLATFORM_GPIO_6 ] = {WICED_P10, WICED_GCI_SECI_OUT      },
        [PLATFORM_GPIO_7 ] = {WICED_P16, WICED_PCM_CLK_I2S_CLK   },
        [PLATFORM_GPIO_8 ] = {WICED_P17, WICED_PCM_SYNC_I2S_WS   },
        [PLATFORM_GPIO_9 ] = {WICED_P26, WICED_GPIO              },      //Default LED 2
        [PLATFORM_GPIO_10] = {WICED_P25, WICED_I2C_1_SCL         },
        [PLATFORM_GPIO_11] = {WICED_P28, WICED_SPI_1_MOSI        },      //Optional LED 1
        [PLATFORM_GPIO_12] = {WICED_P29, WICED_I2C_1_SDA         },
        [PLATFORM_GPIO_13] = {WICED_P33, WICED_UART_2_TXD        },
        [PLATFORM_GPIO_14] = {WICED_P34, WICED_UART_2_RXD        },
        [PLATFORM_GPIO_15] = {WICED_P38, WICED_SPI_1_CLK         },
    };

/* LED configuration */
const wiced_platform_led_config_t platform_led[] =
    {
        [WICED_PLATFORM_LED_2] =
            {
                .gpio          = (wiced_bt_gpio_numbers_t*)&amp;platform_gpio_pins[PLATFORM_GPIO_9].gpio_pin,
                .config        = ( GPIO_OUTPUT_ENABLE | GPIO_PULL_UP ),
                .default_state = GPIO_PIN_OUTPUT_HIGH,
            },

// We can use either LED1 or SPI1 MOSI, by default we are using WICED_P28 for SPI1 MOSI,
// uncomment the following initialization if WICED_P28 is to be used as an LED and set PIN
// functionality in platform_gpio_pins as WICED_GPIO

//        [WICED_PLATFORM_LED_1] =
//            {
//                .gpio          = (wiced_bt_gpio_numbers_t*)&amp;platform_gpio_pins[PLATFORM_GPIO_11].gpio_pin,
//                .config        = ( GPIO_OUTPUT_ENABLE | GPIO_PULL_UP ),
//                .default_state = GPIO_PIN_OUTPUT_HIGH,
//            }
    };
</pre>
<h1>SuperMux Tool</h1>
<p>The SuperMux tool is a GUI for setting the default configurations of the Pins on the chip.  Like all capable MCUs, this chip has PWMs, SPIs, UARTs, GPIOs, I2C, ADCs etc.  Each pin on the chip can do a bunch of different functions, but only one at a time.  Each pin has a multiplexor in front of it that selects the function of that pin.  The SuperMux tool helps you setup the multiplexors for each pin on the chip.</p>
<p>To run the SuperMux tool, first click on your project directory (remember L3_SuperMux).  The select File&#8211;&gt;New&#8211;&gt;WICED SuperMux GPIO Pin Configuration</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-23-42-pm/" rel="attachment wp-att-5468"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.23.42-PM.png" alt="" width="842" height="440" class="alignnone size-full wp-image-5468" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.23.42-PM.png 842w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.23.42-PM-600x314.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.23.42-PM-300x157.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.23.42-PM-768x401.png 768w" sizes="(max-width: 842px) 100vw, 842px" /></a></p>
<p>It will ask you which &#8220;App Name&#8221; you want it to work on.  Since we clicked on the L3_SuperMux app, it uses that name by default.  Press Next</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-23-55-pm/" rel="attachment wp-att-5471"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.23.55-PM.png" alt="" width="660" height="587" class="alignnone size-large wp-image-5471" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.23.55-PM.png 660w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.23.55-PM-600x534.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.23.55-PM-300x267.png 300w" sizes="(max-width: 660px) 100vw, 660px" /></a></p>
<p>The SuperMux Wizard will give you the opportunity to select which pins you want to configure.  It also shows you the default configuration of each of the pins.  In this case just press &#8220;Next&#8221; because we want to configure them all.</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-24-08-pm-2/" rel="attachment wp-att-5483"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.24.08-PM-1.png" alt="" width="661" height="585" class="alignnone size-full wp-image-5483" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.24.08-PM-1.png 661w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.24.08-PM-1-600x531.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.24.08-PM-1-300x266.png 300w" sizes="(max-width: 661px) 100vw, 661px" /></a></p>
<p>Now you will see the functions of the chip and which pins they are assigned to.  Notice that WICED_P28 is assigned as the MOSI of SPI(Slave)_1.  We don&#8217;t want that.</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-24-25-pm/" rel="attachment wp-att-5469"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.24.25-PM.png" alt="" width="722" height="765" class="alignnone size-full wp-image-5469" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.24.25-PM.png 722w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.24.25-PM-600x636.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.24.25-PM-283x300.png 283w" sizes="(max-width: 722px) 100vw, 722px" /></a></p>
<p>Remove the SPI(Slave)_1 by selecting it and then pressing the &#8220;Remove&#8221; button</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-27-32-pm/" rel="attachment wp-att-5475"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.27.32-PM.png" alt="" width="725" height="771" class="alignnone size-large wp-image-5475" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.27.32-PM.png 725w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.27.32-PM-600x638.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.27.32-PM-282x300.png 282w" sizes="(max-width: 725px) 100vw, 725px" /></a></p>
<p>Now your screen will look like this.  In order to add a new pin configuration you can press the little &#8220;+&#8221; at the bottom of the function column.</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-27-48-pm/" rel="attachment wp-att-5474"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.27.48-PM.png" alt="" width="722" height="770" class="alignnone size-large wp-image-5474" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.27.48-PM.png 722w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.27.48-PM-600x640.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.27.48-PM-281x300.png 281w" sizes="(max-width: 722px) 100vw, 722px" /></a></p>
<p>Next press the little &#8220;+&#8221; button and select LED. <a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-24-08-pm/" rel="attachment wp-att-5470"></a></p>
<p><a href="https://iotexpert.com/?attachment_id=5473" rel="attachment wp-att-5473"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.28.01-PM.png" alt="" width="716" height="764" class="alignnone size-large wp-image-5473" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.28.01-PM.png 716w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.28.01-PM-600x640.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.28.01-PM-281x300.png 281w" sizes="(max-width: 716px) 100vw, 716px" /></a></p>
<p>The select which Pin you want assigned to the LED.  In this case we want WICED_P28</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-28-16-pm/" rel="attachment wp-att-5472"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.28.16-PM.png" alt="" width="720" height="768" class="alignnone size-full wp-image-5472" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.28.16-PM.png 720w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.28.16-PM-600x640.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.28.16-PM-281x300.png 281w" sizes="(max-width: 720px) 100vw, 720px" /></a></p>
<p>After you press finish you will notice that it adds a several files to your project.  And you notice that it creates a file called &#8220;makefile.mk.bak&#8221; (which is the backup of the original makefile)</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-30-47-pm/" rel="attachment wp-att-5476"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.30.47-PM.png" alt="" width="359" height="243" class="alignnone size-full wp-image-5476" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.30.47-PM.png 359w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.30.47-PM-300x203.png 300w" sizes="(max-width: 359px) 100vw, 359px" /></a></p>
<p>First look at the makefile and notice that it added the &#8220;L3_SuperMux_pin_config.c&#8221; to the sources and added a CFLAG</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c" ">#
# Lesson 3 - SuperMux
#
APP_SRC +=  L3_SuperMux.c

C_FLAGS += -DWICED_BT_TRACE_ENABLE
C_FLAGS += -DSMUX_CHIP=$(CHIP)
APP_SRC += L3_SuperMux_pin_config.c
</pre>
<p>So, what is up with the  L3_SuperMux_pin_config.c.  OH!!! I See, this is just a replacement for the default platform configuration.  Notice that P28 is now a WICED_GPIO and that it is now defined in the LED list.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c" ">wiced_platform_gpio_t platform_gpio_pins[]=
	{
		[PLATFORM_GPIO_0]	= {WICED_P00, WICED_GPIO},
		[PLATFORM_GPIO_1]	= {WICED_P02, WICED_PCM_OUT_I2S_DO},
		[PLATFORM_GPIO_2]	= {WICED_P04, WICED_PCM_IN_I2S_DI},
		[PLATFORM_GPIO_3]	= {WICED_P06, WICED_GCI_SECI_IN},
		[PLATFORM_GPIO_4]	= {WICED_P10, WICED_GCI_SECI_OUT},
		[PLATFORM_GPIO_5]	= {WICED_P16, WICED_PCM_CLK_I2S_CLK},
		[PLATFORM_GPIO_6]	= {WICED_P17, WICED_PCM_SYNC_I2S_WS},
		[PLATFORM_GPIO_7]	= {WICED_P25, WICED_I2C_1_SCL},
		[PLATFORM_GPIO_8]	= {WICED_P26, WICED_GPIO},
		[PLATFORM_GPIO_9]	= {WICED_P28, WICED_GPIO},
		[PLATFORM_GPIO_10]	= {WICED_P29, WICED_I2C_1_SDA},
		[PLATFORM_GPIO_11]	= {WICED_P33, WICED_UART_2_TXD},
		[PLATFORM_GPIO_12]	= {WICED_P34, WICED_UART_2_RXD},
	};

const wiced_platform_button_config_t platform_button[WICED_PLATFORM_BUTTON_MAX]=
	{
		[WICED_PLATFORM_BUTTON_1] =
			{
				.gpio			= &amp;platform_gpio_pins[PLATFORM_GPIO_0].gpio_pin,
				.config			= (GPIO_INPUT_ENABLE | GPIO_PULL_UP),
				.default_state	= GPIO_PIN_OUTPUT_LOW,
				.button_pressed_value	= GPIO_PIN_OUTPUT_LOW,
			},
	};

const size_t button_count =  (sizeof(platform_button) / sizeof(wiced_platform_button_config_t));


const wiced_platform_led_config_t platform_led[WICED_PLATFORM_LED_MAX]=
	{
		[WICED_PLATFORM_LED_1] =
			{
				.gpio			= &amp;platform_gpio_pins[PLATFORM_GPIO_9].gpio_pin,
				.config			= (GPIO_OUTPUT_ENABLE | GPIO_PULL_UP),
				.default_state	= GPIO_PIN_OUTPUT_HIGH,
			},
		[WICED_PLATFORM_LED_2] =
			{
				.gpio			= &amp;platform_gpio_pins[PLATFORM_GPIO_8].gpio_pin,
				.config			= (GPIO_OUTPUT_ENABLE | GPIO_PULL_UP),
				.default_state	= GPIO_PIN_OUTPUT_HIGH,
			},
	};
</pre>
<p>Now that the pins are configured.  We need to setup the PWM.</p>
<h1>Configure the Clock and the PWM</h1>
<p>Now I will add a little bit of code to the top of  our L3_SuperMux.c to configure the PWM, Clock and Pin.</p>
<p>First add includes for the ACLK and PWM driver.</p>
<pre class="start-line:8 EnlighterJSRAW" data-enlighter-language="c" ">#include "wiced_hal_aclk.h"
#include "wiced_hal_pwm.h"</pre>
<p>Then startup the Clock, Pin and PWM.</p>
<pre class="start-line:17 lang:c decode:true">    wiced_hal_aclk_enable(2000, ACLK1, ACLK_FREQ_1_MHZ );
    wiced_hal_pwm_configure_pin (WICED_GPIO_PIN_LED_1, PWM1 );
    wiced_hal_pwm_start(PWM1, PMU_CLK, 0xFFFF-500, 0xFFFF-999,0);
</pre>
<p>If you want to turn on the PWM you need to do three things</p>
<ol>
<li>Turn on a clock to drive it (line 17) sets the clock frequency to 2000hz</li>
<li>Attach the PWM to a Pin (line 18) attaches PWM 1 to the pin</li>
<li>Turn on the PWM which is a 16-bit up-counting PWM.  When the PWM is reset it will go to 0xFFFF-999 (the period)&#8230; then it will switch at 0xFFFF-500 (the compare value)</li>
</ol>
<p>When you program this your Green LED aka WICED_LED_1 is being driven by the PWM.  And your RED LED is being driven by your firmware.</p>
<h1>Documentation</h1>
<p>All of the hardware blocks on the chip have a set of API functions to help you interface with them.  You can find all of that in the Documentation</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/screen-shot-2018-06-24-at-12-49-33-pm/" rel="attachment wp-att-5480"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.49.33-PM-1024x730.png" alt="" width="1024" height="730" class="alignnone size-large wp-image-5480" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.49.33-PM-1024x730.png 1024w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.49.33-PM-600x428.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.49.33-PM-300x214.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.49.33-PM-768x547.png 768w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-12.49.33-PM.png 1260w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/lesson-3-wiced-bluetooth-the-super-mux-tool/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Lesson 2 &#8211; WICED Bluetooth: Your First Project(s)</title>
		<link>https://iotexpert.com/lesson-2-wiced-bluetooth-your-first-projects/</link>
					<comments>https://iotexpert.com/lesson-2-wiced-bluetooth-your-first-projects/#comments</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Thu, 28 Jun 2018 12:36:32 +0000</pubDate>
				<category><![CDATA[CYW920179Q40EVB-01]]></category>
		<category><![CDATA[Mouser CYW20719 Bluetooth 5.0]]></category>
		<category><![CDATA[WICED]]></category>
		<category><![CDATA[WICED 20719]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=5404</guid>

					<description><![CDATA[Summary For our first project, I am going to stand on the shoulder of giants.  In 1978, Brian Kernighan and Dennis Ritchie published &#8220;The C Programming Language&#8221;.  Here are pictures of my copy. The reason you do &#8220;Hello, World&#8221; is that you want to make sure that your compiler chain, programmer etc are all working [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><span><h1>WICED Bluetooth Using the CYW20719</h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Title</th>
<th >Comment</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/2018/06/23/lesson-0-a-two-hour-wiced-bluetooth-class/">A Two Hour WICED Bluetooth Class</a></td>
<td >WICED Bluetooth Using the CYW20719 in all its glory</td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-1-wiced-bluetooth-a-tour-of-the-resources/">Resources</a></td>
<td ><span>Links to all of the Cypress WICED information including videos, application notes etc.</span></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/">Your First Project</a></td>
<td >Making Hello World &amp; the Blinky LED</td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/">The Super Mux Tool</a></td>
<td >Learning about platforms and the Super Mux Tool</td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-4-wiced-bluetooth-using-snips/">Snips</a></td>
<td >Using the example projects to learn Bluetooth</td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-5-wiced-bluetooth-bluetooth-designer-turn-up-the-radio/">Bluetooth Designer</a></td>
<td >Using the tool to customize a project and get going fast</td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-6-wiced-bluetooth-the-peripheral-comes-alive/">The CCCD &amp; Notification</a></td>
<td >Writing back to the Central</td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-7-wiced-bluetooth-bluetooth-advertising/">Advertising  Beacon</a></td>
<td >Building a beacon project to advertise your custom information </td>
</tr>

<tr><td >8</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-8-wiced-bluetooth-the-advertising-scanner/">Scanner</a></td>
<td >Viewing the world around you</td>
</tr>

<tr><td >9</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-9-wiced-bluetooth-classic-serial-port/">Bluetooth Classic SPP</a></td>
<td >Using the Serial Port Profile to Transmit Lots of Data</td>
</tr>
</tbody></table></div></p>
<p>Source code: </p>
<ul>
<li>git@github.com:iotexpert/wiced_bt_intro.git</li>
<li>https://github.com/iotexpert/wiced_bt_intro</li>
</ul>
<p>&nbsp;</p></span></p>
<h1>Summary</h1>
<p>For our first project, I am going to stand on the shoulder of giants.  In 1978, Brian Kernighan and Dennis Ritchie published &#8220;The C Programming Language&#8221;.  Here are pictures of my copy.</p>
<p><a href="https://iotexpert.com/2017/05/10/implementing-psoc-printf/img_4427/" rel="attachment wp-att-3504"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/05/IMG_4427-e1494407890391-225x300.jpg" alt="" width="225" height="300" class="alignnone wp-image-3504 size-medium" srcset="https://iotexpert.com/wp-content/uploads/2017/05/IMG_4427-e1494407890391-225x300.jpg 225w, https://iotexpert.com/wp-content/uploads/2017/05/IMG_4427-e1494407890391-600x800.jpg 600w, https://iotexpert.com/wp-content/uploads/2017/05/IMG_4427-e1494407890391-768x1024.jpg 768w, https://iotexpert.com/wp-content/uploads/2017/05/IMG_4427-e1494407890391-scaled.jpg 1920w" sizes="(max-width: 225px) 100vw, 225px" /></a> <a href="https://iotexpert.com/2017/05/10/implementing-psoc-printf/img_4426/" rel="attachment wp-att-3505"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/05/IMG_4426-e1494407928888-225x300.jpg" alt="Kernighan &amp; Ritchie" width="225" height="300" class="alignnone wp-image-3505 size-medium" srcset="https://iotexpert.com/wp-content/uploads/2017/05/IMG_4426-e1494407928888-225x300.jpg 225w, https://iotexpert.com/wp-content/uploads/2017/05/IMG_4426-e1494407928888-600x800.jpg 600w, https://iotexpert.com/wp-content/uploads/2017/05/IMG_4426-e1494407928888-768x1024.jpg 768w, https://iotexpert.com/wp-content/uploads/2017/05/IMG_4426-e1494407928888-scaled.jpg 1920w" sizes="(max-width: 225px) 100vw, 225px" /></a></p>
<p>The reason you do &#8220;Hello, World&#8221; is that you want to make sure that your compiler chain, programmer etc are all working correctly with something that is super simple.  The only change that I will make to their classic program is to add the &#8220;Blinking LED&#8221; which is the embedded developers version of &#8220;Hello, World&#8221;.</p>
<p>The concepts that I want to show in this lesson are.</p>
<ol>
<li>How to make a new project &#8211; makefile.mk, &lt;appname&gt;.c</li>
<li>How NOT to make a new project</li>
<li>How to create a &#8220;Make Target&#8221;</li>
<li>CYW920719Q40EVB01 Development Kit</li>
<li>WICED PUART and WICED HCI UART</li>
<li>How to start the bootloader</li>
<li>Where the documentation resides for the WICED 20719 hardware abstraction layer</li>
<li>WICED uses ThreadX RTOS</li>
</ol>
<p>To make this first project the steps are:</p>
<ol>
<li>Make a new folder called wiced_bt_class  in the Apps Folder</li>
<li>Make a new folder called L2_HelloWorld in the wiced_bt_intro Folder</li>
<li>Create a new file called L2_HelloWorld.c</li>
<li>Create a new file called makefile.mk</li>
<li>Add the code to print HelloWorld &amp; blink the LED to L2_HelloWorld.c</li>
<li>Add the secret incantation to makefile.mk to build the project</li>
<li>Create a &#8220;Make Target&#8221;</li>
<li>Connect the development kit to your computer</li>
<li>Attach a serial terminal to the PUART</li>
<li>Run the Make Target to Build and Program</li>
</ol>
<p>Lets do this!</p>
<h1>DO NOT DO File-&gt;New Project</h1>
<p>I always hate to start with a negative statement&#8230; but DO NOT make a file project by doing File-&gt;New Project.  This is used for creating a new Eclipse project, not a new WICED Studio project.  In WICED Studio we use the make external build system.  If you do File-&gt;New Project all hell is going to break loose.  So don&#8217;t do any of the things on this menu:</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-10-41-22-am/" rel="attachment wp-att-5453"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-10.41.22-AM.png" alt="" width="811" height="119" class="alignnone size-full wp-image-5453" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-10.41.22-AM.png 811w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-10.41.22-AM-600x88.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-10.41.22-AM-300x44.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-10.41.22-AM-768x113.png 768w" sizes="(max-width: 811px) 100vw, 811px" /></a></p>
<h1>Hello World &amp; Blinking LED</h1>
<p>Now lets get on with making a WICED Studio Project.  First create a new folder to hold the projects for the Class in the &#8220;Apps&#8221; folder by right-clicking and selecting New-&gt;Folder</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-8-29-50-am/" rel="attachment wp-att-5413"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.29.50-AM.png" alt="" width="492" height="282" class="alignnone size-large wp-image-5413" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.29.50-AM.png 492w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.29.50-AM-300x172.png 300w" sizes="(max-width: 492px) 100vw, 492px" /></a></p>
<p>Give it the name &#8220;wiced_bt_class&#8221;</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-8-31-42-am/" rel="attachment wp-att-5412"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.31.42-AM.png" alt="" width="527" height="586" class="alignnone size-full wp-image-5412" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.31.42-AM.png 527w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.31.42-AM-270x300.png 270w" sizes="(max-width: 527px) 100vw, 527px" /></a></p>
<p>Create a folder to hold the first project called L2_HelloWorld</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-8-48-16-am/" rel="attachment wp-att-5422"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.48.16-AM.png" alt="" width="527" height="163" class="alignnone size-full wp-image-5422" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.48.16-AM.png 527w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.48.16-AM-300x93.png 300w" sizes="(max-width: 527px) 100vw, 527px" /></a></p>
<p>Call the folder L2_HelloWorld</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-8-48-30-am/" rel="attachment wp-att-5421"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.48.30-AM.png" alt="" width="523" height="588" class="alignnone size-large wp-image-5421" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.48.30-AM.png 523w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.48.30-AM-267x300.png 267w" sizes="(max-width: 523px) 100vw, 523px" /></a></p>
<p>Make a new file called L2_HelloWorld.c by right clicking on the L2_HelloWorld folder and selecting New&#8211;&gt;File</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-8-50-47-am/" rel="attachment wp-att-5426"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.50.47-AM.png" alt="" width="536" height="168" class="alignnone size-large wp-image-5426" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.50.47-AM.png 536w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.50.47-AM-300x94.png 300w" sizes="(max-width: 536px) 100vw, 536px" /></a></p>
<p>Give it the name L2_HelloWorld.c</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-8-51-05-am/" rel="attachment wp-att-5425"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.51.05-AM.png" alt="" width="524" height="582" class="alignnone size-large wp-image-5425" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.51.05-AM.png 524w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.51.05-AM-270x300.png 270w" sizes="(max-width: 524px) 100vw, 524px" /></a></p>
<p>Make a new file called makefile.mk by right clicking on the L2_HelloWorld directory and selecting New-&gt;File</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-8-51-23-am/" rel="attachment wp-att-5424"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.51.23-AM.png" alt="" width="543" height="189" class="alignnone size-large wp-image-5424" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.51.23-AM.png 543w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.51.23-AM-300x104.png 300w" sizes="(max-width: 543px) 100vw, 543px" /></a></p>
<p>and giving it the name makefile.mk</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-8-51-36-am/" rel="attachment wp-att-5423"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.51.36-AM.png" alt="" width="528" height="586" class="alignnone size-full wp-image-5423" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.51.36-AM.png 528w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.51.36-AM-270x300.png 270w" sizes="(max-width: 528px) 100vw, 528px" /></a></p>
<p>Add some code to the L2_HelloWorld.c</p>
<pre class="lang:c decode:true ">#include "wiced.h"
#include "sparcommon.h"
#include "wiced_platform.h"
#include "wiced_rtos.h"
#include "wiced_hal_gpio.h"
#include "wiced_bt_trace.h"

APPLICATION_START()
{
    wiced_set_debug_uart(WICED_ROUTE_DEBUG_TO_PUART);

    WICED_BT_TRACE("Hello, World\n");
    while(1)
    {

        WICED_BT_TRACE("Setting 0\n");
        wiced_hal_gpio_set_pin_output(WICED_GPIO_PIN_LED_2,0);
        wiced_rtos_delay_milliseconds(500,KEEP_THREAD_ACTIVE );
        WICED_BT_TRACE("Setting 1\n");
        wiced_hal_gpio_set_pin_output(WICED_GPIO_PIN_LED_2,1);
        wiced_rtos_delay_milliseconds(500,KEEP_THREAD_ACTIVE );
    }
}</pre>
<p>Add the secret incantation to the makefile.mk</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#
# Lesson 2 - Hello, World
#
APP_SRC +=  L2_HelloWorld.c

C_FLAGS += -DWICED_BT_TRACE_ENABLE

</pre>
<p>Create a make target</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-8-39-46-am/" rel="attachment wp-att-5419"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.39.46-AM.png" alt="" width="317" height="296" class="alignnone size-large wp-image-5419" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.39.46-AM.png 317w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.39.46-AM-300x280.png 300w" sizes="(max-width: 317px) 100vw, 317px" /></a></p>
<p>The make target has a <strong>VERY</strong> specific format.  It is:</p>
<p>directory.directory.appname-platform download</p>
<p>In our case we have all of our projects in a directory called &#8220;wiced_bt_class&#8221;.  Then we have a directory called &#8220;L2_HelloWorld&#8221; which holds the exact project.  And our platform name is &#8220;CYW920719Q40EVB_01&#8221;</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-8-56-44-am/" rel="attachment wp-att-5428"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.56.44-AM.png" alt="" width="571" height="380" class="alignnone size-full wp-image-5428" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.56.44-AM.png 571w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.56.44-AM-300x200.png 300w" sizes="(max-width: 571px) 100vw, 571px" /></a></p>
<h1>Connect the Development Kit To Your Computer</h1>
<p>When you plug in your development kit, it will USB enumerate a TWO serial ports.  One of the serial ports (the first one) is called the &#8220;WICED HCI UART&#8221;.  The second serial port is called the &#8220;WICED Peripheral UART&#8221; (this is often abbreviated &#8220;PUART&#8221;)</p>
<p>One of the key things that the WICED HCI UART is used as is a UART to download new code to the bootloader.</p>
<p>The PUART is used as a general purpose serial port.  When we call this function it causes all of our &#8220;WICED_BT_TRACE&#8221; outputs to go to the the PUART.</p>
<pre class="lang:c decode:true ">    wiced_set_debug_uart(WICED_ROUTE_DEBUG_TO_PUART);
</pre>
<p>You can see these two UARTs on a PC by running the device manager.</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-9-21-00-am/" rel="attachment wp-att-5435"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.21.00-AM.png" alt="" width="389" height="618" class="alignnone size-large wp-image-5435" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.21.00-AM.png 389w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.21.00-AM-189x300.png 189w" sizes="(max-width: 389px) 100vw, 389px" /></a></p>
<p>You can see COM17 is the &#8220;WICED HCI UART&#8221; and COM18 is the &#8220;WICED Peripheral UART&#8221;</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-9-21-30-am/" rel="attachment wp-att-5434"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.21.30-AM.png" alt="" width="778" height="571" class="alignnone size-full wp-image-5434" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.21.30-AM.png 778w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.21.30-AM-600x440.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.21.30-AM-300x220.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.21.30-AM-768x564.png 768w" sizes="(max-width: 778px) 100vw, 778px" /></a></p>
<p>On my Mac I use the program &#8220;Serial&#8221; which I downloaded from the App Store.</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-9-02-04-am/" rel="attachment wp-att-5432"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.02.04-AM.png" alt="" width="371" height="475" class="alignnone size-full wp-image-5432" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.02.04-AM.png 371w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.02.04-AM-234x300.png 234w" sizes="(max-width: 371px) 100vw, 371px" /></a></p>
<p>When I run Serial and then to open a Port</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-9-26-33-am/" rel="attachment wp-att-5436"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.26.33-AM.png" alt="" width="340" height="199" class="alignnone size-full wp-image-5436" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.26.33-AM.png 340w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.26.33-AM-300x176.png 300w" sizes="(max-width: 340px) 100vw, 340px" /></a></p>
<p>You can see the two UARTs.</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-9-01-17-am/" rel="attachment wp-att-5431"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.01.17-AM.png" alt="" width="528" height="379" class="alignnone size-full wp-image-5431" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.01.17-AM.png 528w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.01.17-AM-300x215.png 300w" sizes="(max-width: 528px) 100vw, 528px" /></a></p>
<p>In order to see the output I will connect to the port with the settings</p>
<ul>
<li>115200 Baud</li>
<li>8-n-1 (Data bits, Parity, Stop Bits)</li>
</ul>
<p>With my PC I typically use Putty (remember it was COM18 from the screen above)</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-9-32-46-am/" rel="attachment wp-att-5437"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.32.46-AM.png" alt="" width="452" height="438" class="alignnone size-full wp-image-5437" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.32.46-AM.png 452w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.32.46-AM-300x291.png 300w" sizes="(max-width: 452px) 100vw, 452px" /></a></p>
<p>On the Mac program serial you can configure it with Terminal-&gt;Settings</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-9-35-22-am/" rel="attachment wp-att-5438"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.35.22-AM.png" alt="" width="433" height="88" class="alignnone size-full wp-image-5438" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.35.22-AM.png 433w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.35.22-AM-300x61.png 300w" sizes="(max-width: 433px) 100vw, 433px" /></a></p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-9-35-02-am/" rel="attachment wp-att-5439"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.35.02-AM.png" alt="" width="465" height="530" class="alignnone size-large wp-image-5439" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.35.02-AM.png 465w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.35.02-AM-263x300.png 263w" sizes="(max-width: 465px) 100vw, 465px" /></a></p>
<h1>Program your Development Kit</h1>
<p>In the Make Target window you should see a bunch of &#8220;targets&#8221;.  You probably have a bunch more targets, which came in your installation of WICED Studio by default, but I deleted a bunch of them so I could just see the ones that I created.</p>
<p>To build and program your project, double click the make target we made before.</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-9-40-49-am/" rel="attachment wp-att-5441"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.40.49-AM.png" alt="" width="518" height="245" class="alignnone size-full wp-image-5441" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.40.49-AM.png 518w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.40.49-AM-300x142.png 300w" sizes="(max-width: 518px) 100vw, 518px" /></a></p>
<p>When you look in the console you should see something like this:</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-9-45-45-am/" rel="attachment wp-att-5443"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.45.45-AM.png" alt="" width="863" height="690" class="alignnone size-full wp-image-5443" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.45.45-AM.png 863w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.45.45-AM-600x480.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.45.45-AM-300x240.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.45.45-AM-768x614.png 768w" sizes="(max-width: 863px) 100vw, 863px" /></a></p>
<p>And when you look at your serial terminal you will see this:</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-8-59-38-am/" rel="attachment wp-att-5430"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.59.38-AM.png" alt="" width="624" height="340" class="alignnone size-full wp-image-5430" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.59.38-AM.png 624w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.59.38-AM-600x327.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-8.59.38-AM-300x163.png 300w" sizes="(max-width: 624px) 100vw, 624px" /></a></p>
<p>And you should also see the blinking LED!!!</p>
<h1>Start the Bootloader</h1>
<p>If you get this message there are three posibilites</p>
<ol>
<li>The kit isn&#8217;t plugged in</li>
<li>The driver didn&#8217;t install properly</li>
<li>The bootloader wont start</li>
</ol>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/screen-shot-2018-06-24-at-9-42-02-am/" rel="attachment wp-att-5442"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.42.02-AM.png" alt="" width="709" height="249" class="alignnone size-full wp-image-5442" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.42.02-AM.png 709w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.42.02-AM-600x211.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-24-at-9.42.02-AM-300x105.png 300w" sizes="(max-width: 709px) 100vw, 709px" /></a></p>
<p>Check the first two&#8230; and if that doesnt work then what this means is that the bootloader is not listening on the WICED HCI UART.  In order to fix this you need to press reset and hold down the button called &#8220;Recover&#8221;.  Then release the reset, then release the recover button.  What does this do?  Simple, when the chip comes out of reset, if the recover button is pressed, the chip starts the bootloader instead of the main application.</p>
<p>Here is a picture of the bottom corner of the board.  The button circled in Green is the &#8220;Recover&#8221;.  The button in Red is &#8220;Reset&#8221; and the Blue surrounds the LED circuit.</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/img_5967/" rel="attachment wp-att-5448"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/IMG_5967-1024x768.jpg" alt="" width="1024" height="768" class="alignnone size-large wp-image-5448" srcset="https://iotexpert.com/wp-content/uploads/2018/06/IMG_5967-1024x768.jpg 1024w, https://iotexpert.com/wp-content/uploads/2018/06/IMG_5967-600x450.jpg 600w, https://iotexpert.com/wp-content/uploads/2018/06/IMG_5967-300x225.jpg 300w, https://iotexpert.com/wp-content/uploads/2018/06/IMG_5967-768x576.jpg 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>The two LEDs are labeled LED1 and LED2.  LED2 is the Red one, LED1 is the Green one.  The dip switches circled in Blue connect or disconnect the LEDs from the CYW20719.  In my case you can see (barely) that the switch is set to On.  Both of these LEDs are active LOW (0 turns them on)</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/img_5966/" rel="attachment wp-att-5447"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/IMG_5966-1024x574.jpg" alt="" width="1024" height="574" class="alignnone size-large wp-image-5447" srcset="https://iotexpert.com/wp-content/uploads/2018/06/IMG_5966-1024x574.jpg 1024w, https://iotexpert.com/wp-content/uploads/2018/06/IMG_5966-600x337.jpg 600w, https://iotexpert.com/wp-content/uploads/2018/06/IMG_5966-300x168.jpg 300w, https://iotexpert.com/wp-content/uploads/2018/06/IMG_5966-768x431.jpg 768w, https://iotexpert.com/wp-content/uploads/2018/06/IMG_5966.jpg 1198w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/lesson-2-wiced-bluetooth-your-first-projects/feed/</wfw:commentRss>
			<slash:comments>10</slash:comments>
		
		
			</item>
		<item>
		<title>Serial Wire View with PSOC4</title>
		<link>https://iotexpert.com/serial-wire-view-with-psoc4/</link>
					<comments>https://iotexpert.com/serial-wire-view-with-psoc4/#respond</comments>
		
		<dc:creator><![CDATA[Darrin Vallis]]></dc:creator>
		<pubDate>Sat, 18 Nov 2017 01:17:08 +0000</pubDate>
				<category><![CDATA[CY8CKIT-042]]></category>
		<category><![CDATA[CY8CKIT-044]]></category>
		<category><![CDATA[Devices]]></category>
		<category><![CDATA[Embedded Design]]></category>
		<category><![CDATA[PSoC 4000S]]></category>
		<category><![CDATA[PSoC 4200]]></category>
		<category><![CDATA[PSoC Creator]]></category>
		<category><![CDATA[PSoC4 BLE]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=4707</guid>

					<description><![CDATA[I use PSOC4 to invent all kinds of unique solutions for customers. Usually, they want them field upgradeable to deploy new features or fix bugs. Fortunately Cypress has a great I2C boot loader to meet this need, so I use the heck out of it. Cypress has a great debugger built into PSOC Creator which [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>I use PSOC4 to invent all kinds of unique solutions for customers. Usually, they want them field upgradeable to deploy new features or fix bugs. Fortunately Cypress has a great <a href="http://www.cypress.com/documentation/application-notes/an86526-psocr-4-and-psoc-analog-coprocessor-i2c-bootloader-zh">I2C boot loader</a> to meet this need, so I use the heck out of it.</p>
<p>Cypress has a great debugger built into <a href="http://www.cypress.com/products/psoc-creator-integrated-design-environment-ide">PSOC Creator</a> which fully supports all the ARM Serial Wire Debug protocols such as breakpoints, single step, memory, register viewing etc. However, when you are running a boot loader <em>the debugger does not work!</em> Why not? Because with a boot loader there are two applications resident in PSOC4: The boot loader and application. This is not supported by Cypress implementation of SWD.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/bootloader.jpg"><img loading="lazy" decoding="async" width="300" height="155" class="alignnone wp-image-4710 size-medium" alt="" src="https://iotexpert.com/wp-content/uploads/2017/11/bootloader-300x155.jpg" srcset="https://iotexpert.com/wp-content/uploads/2017/11/bootloader-300x155.jpg 300w, https://iotexpert.com/wp-content/uploads/2017/11/bootloader-600x311.jpg 600w, https://iotexpert.com/wp-content/uploads/2017/11/bootloader.jpg 653w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>Where does this leave you, the intrepid code developer, when debugging a boot loader project? Personally, I have used all kinds of methods: debug UART interface, debug I2C interface, bang out states on pins, debug Bluetooth interface &#8230; and on and on. You get the idea. All these methods burn a communications interface and require extra pins on the chip. Sometimes that&#8217;s not possible.</p>
<p>The issue recently came to a head when a customer very nearly in production experienced a boot loader failure. One system out of a few thousand was &#8220;bricked&#8221; when they tried to field  update in the lab. Their pinout is frozen, they can&#8217;t add new hardware so how do we look inside PSOC4 and see what&#8217;s going on?</p>
<p>I woke up at 2 AM and thought &#8220;Ah Ha! SWV!&#8221; (Yes, I Am A Geek) Serial Wire View is an ARM native debug protocol that let&#8217;s you XRAY the insides of any ARM MCU <em>with the right interface</em>. SWV is a protocol which runs on the SWD pins (clock and data) but also needs the Serial Wire Output (SWO) pin. Cypress left the SWO pin and associated IP off of PSOC4 to save die cost, foiling my great idea. Brief interlude to drink and bang head on desk.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/3272886-coresight-debug.png"><img loading="lazy" decoding="async" width="300" height="222" class="aligncenter wp-image-4712 size-medium" alt="" src="https://iotexpert.com/wp-content/uploads/2017/11/3272886-coresight-debug-300x222.png" srcset="https://iotexpert.com/wp-content/uploads/2017/11/3272886-coresight-debug-300x222.png 300w, https://iotexpert.com/wp-content/uploads/2017/11/3272886-coresight-debug-600x443.png 600w, https://iotexpert.com/wp-content/uploads/2017/11/3272886-coresight-debug-768x567.png 768w, https://iotexpert.com/wp-content/uploads/2017/11/3272886-coresight-debug-1024x756.png 1024w, https://iotexpert.com/wp-content/uploads/2017/11/3272886-coresight-debug.png 1190w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>Fortunately, I don&#8217;t give up easily. At least my subconscious does not. Woke up the next night thinking &#8220;Ah Ha!&#8221; again. Wife was mildly annoyed, but tolerates my idiosyncrasies.</p>
<p>Cypress has a nice software UART transmitter implementation. I shamelessly stole it, modified for my purposes and created a custom component. (It&#8217;s pretty easy to do this by the way) Baud rate was modified to 230 KBps and the output pin forced to a specific pin with a control file.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/dtview2.jpg"><img loading="lazy" decoding="async" width="767" height="301" class="alignnone wp-image-4717 size-full" alt="" src="https://iotexpert.com/wp-content/uploads/2017/11/dtview2.jpg" srcset="https://iotexpert.com/wp-content/uploads/2017/11/dtview2.jpg 767w, https://iotexpert.com/wp-content/uploads/2017/11/dtview2-600x235.jpg 600w, https://iotexpert.com/wp-content/uploads/2017/11/dtview2-300x118.jpg 300w" sizes="(max-width: 767px) 100vw, 767px" /></a></p>
<p>Once the component is in place, you can use its _DView_Printf( ) API call to display any debug data. Here is an example:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/code.jpg"><img loading="lazy" decoding="async" width="816" height="227" class="alignnone size-full wp-image-4723" alt="" src="https://iotexpert.com/wp-content/uploads/2017/11/code.jpg" srcset="https://iotexpert.com/wp-content/uploads/2017/11/code.jpg 816w, https://iotexpert.com/wp-content/uploads/2017/11/code-600x167.jpg 600w, https://iotexpert.com/wp-content/uploads/2017/11/code-300x83.jpg 300w, https://iotexpert.com/wp-content/uploads/2017/11/code-768x214.jpg 768w" sizes="(max-width: 816px) 100vw, 816px" /></a></p>
<p>More about that output pin. Cypress sells a tool for programming and debugging PSOC called <a href="http://www.cypress.com/documentation/development-kitsboards/cy8ckit-002-psoc-miniprog3-program-and-debug-kit">CY8CKIT-002</a>, aka MiniProg3. The programming connector consists of VDD, GND, reset, SWD clock and SWD data as shown below.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/Header.jpg"><img loading="lazy" decoding="async" width="300" height="192" class="alignnone size-medium wp-image-4719" alt="" src="https://iotexpert.com/wp-content/uploads/2017/11/Header-300x192.jpg" srcset="https://iotexpert.com/wp-content/uploads/2017/11/Header-300x192.jpg 300w, https://iotexpert.com/wp-content/uploads/2017/11/Header-600x384.jpg 600w, https://iotexpert.com/wp-content/uploads/2017/11/Header-768x492.jpg 768w, https://iotexpert.com/wp-content/uploads/2017/11/Header.jpg 814w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>Since we can&#8217;t use SWD protocol for debugging anyway, we can change the pins from SWD to normal GPIO. <em>The pins still function for programming</em>. By default they are in SWD mode as shown.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/SWD_Pins.jpg"><img loading="lazy" decoding="async" width="300" height="194" class="alignnone size-medium wp-image-4720" alt="" src="https://iotexpert.com/wp-content/uploads/2017/11/SWD_Pins-300x194.jpg" srcset="https://iotexpert.com/wp-content/uploads/2017/11/SWD_Pins-300x194.jpg 300w, https://iotexpert.com/wp-content/uploads/2017/11/SWD_Pins.jpg 587w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>Going to the system tab of the .CYDWR file, we can change them to GPIO.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/ChangeToGPIO.jpg"><img loading="lazy" decoding="async" width="634" height="258" class="alignnone wp-image-4721 size-full" alt="" src="https://iotexpert.com/wp-content/uploads/2017/11/ChangeToGPIO.jpg" srcset="https://iotexpert.com/wp-content/uploads/2017/11/ChangeToGPIO.jpg 634w, https://iotexpert.com/wp-content/uploads/2017/11/ChangeToGPIO-600x244.jpg 600w, https://iotexpert.com/wp-content/uploads/2017/11/ChangeToGPIO-300x122.jpg 300w" sizes="(max-width: 634px) 100vw, 634px" /></a></p>
<p>Once we do that, the pins look like this. Here&#8217;s the trick. We now assign the TX output of our DTView component to pin 3[2], which is available  on the SWD programming header, pin 5.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/TX-UART.jpg"><img loading="lazy" decoding="async" width="300" height="204" class="alignnone size-medium wp-image-4722" alt="" src="https://iotexpert.com/wp-content/uploads/2017/11/TX-UART-300x204.jpg" srcset="https://iotexpert.com/wp-content/uploads/2017/11/TX-UART-300x204.jpg 300w, https://iotexpert.com/wp-content/uploads/2017/11/TX-UART.jpg 533w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>Can you see where we are going with this? Printf( ) data is now coming out of PSOC4 on pin 3[2], easily accessible on our debug header. This is where MiniProg3 comes in. It can actually receive data as a 230 KBps RX UART on its XRES pin. Weird, right? By building a simple interface cable we can get the data from your debug header into MiniProg3.</p>
<p>MiniProg3 XRES &#8212;&#8212; SWD HEADER pin 5</p>
<p>MiniProg3   GND &#8212;&#8212; SWD HEADER pin 2</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/20171114_102729.jpg"><img loading="lazy" decoding="async" width="653" height="490" class="alignnone wp-image-4726 size-full" alt="" src="https://iotexpert.com/wp-content/uploads/2017/11/20171114_102729.jpg" srcset="https://iotexpert.com/wp-content/uploads/2017/11/20171114_102729.jpg 653w, https://iotexpert.com/wp-content/uploads/2017/11/20171114_102729-600x450.jpg 600w, https://iotexpert.com/wp-content/uploads/2017/11/20171114_102729-300x225.jpg 300w" sizes="(max-width: 653px) 100vw, 653px" /></a></p>
<p>However, MiniProg3 does not show up as a COM port on your PC, so how do we the data? It needs to be accessed by a host application running the PP_COM API. This is documented under <em>PSOC Programmer Component Object Model COM Interface Guide</em>, Cypress specification <span style="font-family: Arial;font-size: xx-small"></span>001-45209. If you installed PSOC Creator or Programmer, this document is actually on your PC under C:\Program Files (x86)\Cypress\Programmer\Documents. Engineers don&#8217;t like to read instructions. Amazing what you can find when you do.</p>
<p>I wrote a simple  console application which opens MiniProg3 using PP_COM, retrieves data from the serial RX pin via USB and displays it like a simple terminal program. Voila! You now have a serial debugger that works for any PSOC4 project using MiniProg3 as your USB to serial dongle.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/DTViewOutput.jpg"><img loading="lazy" decoding="async" width="1024" height="388" class="alignnone size-large wp-image-4728" alt="" src="https://iotexpert.com/wp-content/uploads/2017/11/DTViewOutput-1024x388.jpg" srcset="https://iotexpert.com/wp-content/uploads/2017/11/DTViewOutput-1024x388.jpg 1024w, https://iotexpert.com/wp-content/uploads/2017/11/DTViewOutput-600x227.jpg 600w, https://iotexpert.com/wp-content/uploads/2017/11/DTViewOutput-300x114.jpg 300w, https://iotexpert.com/wp-content/uploads/2017/11/DTViewOutput-768x291.jpg 768w, https://iotexpert.com/wp-content/uploads/2017/11/DTViewOutput.jpg 1111w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Customer was really happy with this. We were able to immediately see his problem and fixed it in about 5 minutes.</p>
<p>Finally, here are all the source files</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/DTView-Firmware.zip">DTView Firmware</a> : PSOC Creator example project and DTView component</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/DTViewer-Setup.zip">DTViewer Binary</a> : Installer for DTViewer console</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/ViewerSource.zip">ViewerSource</a> : Complete source code for DTViewer console (Requires Visual Studio 2015)</p>
<p>That&#8217;s all. Have fun with the new debugging tool.</p>
<p>DTV</p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/serial-wire-view-with-psoc4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>PSoC4 Boot Sequence (Part 2) &#8211; Creating the Exception Table using the Linker</title>
		<link>https://iotexpert.com/psoc4-boot-sequence-part-2-creating-the-exception-table-using-the-linker/</link>
					<comments>https://iotexpert.com/psoc4-boot-sequence-part-2-creating-the-exception-table-using-the-linker/#comments</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Tue, 18 Apr 2017 11:00:15 +0000</pubDate>
				<category><![CDATA[PSoC 4200]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=3034</guid>

					<description><![CDATA[Summary of the PSoC4 Boot Sequence In the previous post I took you through the first part of the PSoC4 Boot Sequence.  I traced from the power on of the chip to the beginning of the &#8220;Reset()&#8221; function.  In this post I will trace the steps that were required to get the reset vector and stack [&#8230;]]]></description>
										<content:encoded><![CDATA[<h2>Summary of the PSoC4 Boot Sequence</h2>
<p>In the previous post I took you through the first part of the PSoC4 Boot Sequence.  I traced from the power on of the chip to the beginning of the &#8220;Reset()&#8221; function.  In this post I will trace the steps that were required to get the reset vector and stack pointer set and programmed into the flash of the PSoC4 at the right place.</p>
<p>We know that you program the chip with a hex file which is essentially a file with a list of addresses and values.  But how to you get a hex file?  And how do you get the Reset Vector and Stack Pointer into the hex file?  In order to create a hex file there are several steps required.</p>
<ol>
<li>Compile C &#8211;&gt; Assembly Listing File then Assemble listing &#8211;&gt; Objectfiles</li>
<li>Link object files &#8211;&gt; into ELF file</li>
<li>Convert ELF &#8211;&gt; Hex file</li>
</ol>
<h2>PSoC4 Boot Sequence: Compile and Assemble Program</h2>
<p>Each C file in your project is turned into an ARM assembly language program by the compiler.  You can see the ARM assembly language programs in &#8220;.lst&#8221; files.  You can find your project listing files by clicking on the &#8220;Results&#8221; tab in the workplace explorer then selecting the &#8220;listing files&#8221; folder under your project.  In the screenshot below I am showing you the &#8220;Cm0Start.lst&#8221; which is the ARM assembly language file from the Cm0Start.c.  You will notice that there is one listing file for each of the C files in your project.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-9.33.37-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-9.33.37-AM.png" alt="PSoC4 Boot Sequence: ARM Assembly Language" width="2172" height="1184" class="alignnone wp-image-3036 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-9.33.37-AM.png 2172w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-9.33.37-AM-600x327.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-9.33.37-AM-300x164.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-9.33.37-AM-768x419.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-9.33.37-AM-1024x558.png 1024w" sizes="(max-width: 2172px) 100vw, 2172px" /></a></p>
<p>The next step in the process is for the Assembler to turns the listing files into object files.  Each object file has the hex bytes that represent your program and data.  It also defines which &#8220;section&#8221; that the code and data belong too.  The .0 also has a list of symbols that it doesn&#8217;t know the address of e.g. the address of functions and data in other files.  In order to see the object files you need to use the windows explorer (we don&#8217;t attach them to the workplace explorer)</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-9.51.54-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-9.51.54-AM.png" alt="" width="1554" height="1426" class="alignnone size-full wp-image-3037" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-9.51.54-AM.png 1554w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-9.51.54-AM-600x551.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-9.51.54-AM-300x275.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-9.51.54-AM-768x705.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-9.51.54-AM-1024x940.png 1024w" sizes="(max-width: 1554px) 100vw, 1554px" /></a></p>
<h2>PSoC4 Boot Sequence: Linker Configuration</h2>
<p>The linker is responsible for:</p>
<ol>
<li>Combining all of the .o files into one file</li>
<li>Assigning actual addresses for all of the symbols e.g. variables and functions</li>
</ol>
<p>In order for the linker to do its job, it needs a linker script.  Cypress supports three toolchains: GCC, ARM MDK and IAR.  Each one of the toolchains has different syntax, form etc. for the linker script.  This is painful, but it is made worse by the fact that the linker script language is rather esoteric.  PSoC Creator makes a linker script for all three of the tool chains.  You can find those files called &#8220;cm0gcc.ld&#8221; (the GCC linker file), Cm0Iar.icf (the IAR linker file) and Cm0RealView.scat (the MDK linker file) in the workspace explorer under Generated_Source&#8211;&gt;PSoC4&#8211;&gt;cy_boot</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.06.54-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.06.54-AM.png" alt="PSoC4 Boot Sequence: Linker File" width="2008" height="1224" class="alignnone wp-image-3038 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.06.54-AM.png 2008w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.06.54-AM-600x366.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.06.54-AM-300x183.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.06.54-AM-768x468.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.06.54-AM-1024x624.png 1024w" sizes="(max-width: 2008px) 100vw, 2008px" /></a></p>
<p>There is quite a bit going on in the linker file.  In fact the GCC linker file for PSoC4M is 470 lines long.  However, there are two basic commands in the linker file.</p>
<p>The &#8220;Memory&#8221; command which defines the address and size of the different types of memory in the system.  Each block of memory is sometimes called a &#8220;region&#8221;, but the Linker words &#8220;region&#8221; and &#8220;section&#8221; and &#8220;segment&#8221; are used somewhat erratically in the parlance.  In this PSoC4M there is 128K of Flash that starts at address 0x00000000 and 16K of RAM which starts at address 0x20000000.  You can see the &#8220;Memory&#8221; command on lines 29-33 of the GCC linker script.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.17.49-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.17.49-AM.png" alt="PSoC4 Boot Sequence: Memory Layout" width="972" height="182" class="alignnone wp-image-3040 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.17.49-AM.png 972w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.17.49-AM-600x112.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.17.49-AM-300x56.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.17.49-AM-768x144.png 768w" sizes="(max-width: 972px) 100vw, 972px" /></a></p>
<p>The second big command in the linker file is &#8220;SECTIONS&#8221;.  After the sections command there is a list of [input] section names and where they belong (aka their address).   When you look around on the internet you will find that sometimes the word &#8220;section&#8221; is used interchangeably with the word &#8220;segment&#8221;.  Unfortunately there does not appear to be a canonical definition of either of these words. There are three main section/segments</p>
<ul>
<li>bss &#8211; this section contains variables which should be initialized to zero before main starts</li>
<li>data &#8211; this section contains variables which need to be initialized to some specific value</li>
<li>text &#8211; this section contains your program</li>
</ul>
<p>Here is a screenshot of the part of the GCC linker file that includes the definition of where the PSoC4 ARM exception vectors are located.  This starts on line 72 where the &#8220;SECTIONS&#8221; command is issued.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.22.43-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.22.43-AM.png" alt="PSoC4 Boot Sequence: Linker Section Table" width="1938" height="1034" class="alignnone wp-image-3041 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.22.43-AM.png 1938w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.22.43-AM-600x320.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.22.43-AM-300x160.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.22.43-AM-768x410.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-10.22.43-AM-1024x546.png 1024w" sizes="(max-width: 1938px) 100vw, 1938px" /></a></p>
<p>The section command defines the a list of sections and the address of the sections.  Inside of the linker there is an &#8220;address pointer&#8221; which keeps track the current address in the system.  As it loads sections into the program it increments the address pointer so that it knows the final address of symbols.</p>
<p>In the above listing you see on line 87 that a section called &#8220;.text&#8221; belongs starting at address &#8220;appl_start&#8221;.  The linker code on lines 75&#8211;&gt;80 is used to support bootloading programs with multiple application.  However, in this case we have only one application and no bootloader.  As a result nothing is loaded and &#8220;appl_start&#8221; is set to 0x00000000 which is also known as the first location in Flash.  Line 92 tells the linker to put the code in the section &#8220;*.romvectors&#8221; next.  Now we need to find the code that is marked in some .c file as belonging to the section &#8220;romvectors&#8221;.  I will come back to the linker script in a later article.</p>
<h2>Cm0Start.c the Heart of the PSoC4 Boot Sequence</h2>
<p>After digging through the beginning of the linker script and putting a breakpoint on the reset vector we know that the vector table is in a section named &#8220;romvectors&#8221; and we know that the 2nd entry in the table is the address of the function &#8220;Reset()&#8221;.  So that leaves us with the question:  Where are the &#8220;romvectors&#8221; defined?  After using the PSoC Creator search functionality I find this block of code.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.04.13-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.04.13-PM.png" alt="PSoC4 Boot Sequence: Exception Vector Table" width="1490" height="1136" class="alignnone wp-image-3048 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.04.13-PM.png 1490w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.04.13-PM-600x457.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.04.13-PM-300x229.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.04.13-PM-768x586.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.04.13-PM-1024x781.png 1024w" sizes="(max-width: 1490px) 100vw, 1490px" /></a></p>
<p>That nested mess of #defines and #ifdefs is a bit intimidating&#8230; but it was all put there to support the three different compilers.  If you boil it down, the first thing you will see is line 462 tells the compiler to put the next block of code into the &#8220;.romvectors&#8221; section.  Bingo! that is exactly what we were looking for.  Then on line 464 you can see that we define an array of type &#8220;cysisraddress&#8221;.  It turns out that &#8220;cyisraddress&#8221; is just a function pointer.  OK.</p>
<p>Now dig a little bit more and you can see that line 467 defines the address of the initial stack pointer as CY_SYS_INITIAL_STACK_POINTER.  This address is the last location in the RAM.  Then on line 471 we put the address of the Reset() function, then we put in two entries for the NMI and hard fault handers.  The &#8220;IntDefaultHandler&#8221; is an infinite while(1){} which hangs the processor.  This function is also in the Cm0Start.c file.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.23.54-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.23.54-PM.png" alt="PSoC4 Boot Sequence: Default Exception Handler" width="1532" height="1204" class="alignnone wp-image-3049 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.23.54-PM.png 1532w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.23.54-PM-600x472.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.23.54-PM-300x236.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.23.54-PM-768x604.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.23.54-PM-1024x805.png 1024w" sizes="(max-width: 1532px) 100vw, 1532px" /></a></p>
<h2>Stack Pointer</h2>
<p>Earlier I said &#8220;.. the address of the initial stack pointer.  This address is the last location in the RAM.&#8221;  How does that get to be?  Well if you hover over CY_SYS_INITIAL_STACK_POINTER you will find that it is a #define for the symbol &#8220;__cy_stack&#8221;.  Then when you look in the linker script you will find:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.05.32-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.05.32-PM.png" alt="PSoC4 Boot Sequence: Stack Pointer Configuration" width="1126" height="218" class="alignnone wp-image-3054 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.05.32-PM.png 1126w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.05.32-PM-600x116.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.05.32-PM-300x58.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.05.32-PM-768x149.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.05.32-PM-1024x198.png 1024w" sizes="(max-width: 1126px) 100vw, 1126px" /></a></p>
<p>You can also see that the end of the heap is defined as the address of __cy_stack &#8211; 0x800.   The 0x800 must be the size of the stack&#8230; and it is&#8230; you define it in on the system resources tab of the &#8220;design wide resources&#8221;</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.07.57-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.07.57-PM.png" alt="PSoC4 Boot Sequence: Stack and Heap Configuration" width="1718" height="1052" class="alignnone wp-image-3055 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.07.57-PM.png 1718w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.07.57-PM-600x367.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.07.57-PM-300x184.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.07.57-PM-768x470.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.07.57-PM-1024x627.png 1024w" sizes="(max-width: 1718px) 100vw, 1718px" /></a></p>
<p>The final thing to look at with regards to the stack is linker file definition of the stack (and heap).  On line 258 you can see that the stack starts at the address __cystack &#8211; 0x800.  This address is also known as the end of the RAM minus the size of the stack (remember that in ARM the stack builds down towards lower addresses)</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.54.25-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.54.25-PM.png" alt="PSoC4 Boot Sequence: Stack and Heap Linker Configuration" width="1448" height="622" class="alignnone wp-image-3053 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.54.25-PM.png 1448w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.54.25-PM-600x258.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.54.25-PM-300x129.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.54.25-PM-768x330.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.54.25-PM-1024x440.png 1024w" sizes="(max-width: 1448px) 100vw, 1448px" /></a></p>
<h2>Test1.map</h2>
<p>The last link in the chain is the linker map file.  You can find that file in the Test1&#8211;&gt;CortexM0&#8211;&gt;ARM_GCC_541&#8211;&gt;Debug&#8211;&gt;Listing Files directory.  The map file is message output file of the linker.  You can see the final resting place of all of the symbols. In the screenshot below you can see that the &#8220;.romvectors&#8221; segment started at address 0x0 and ended at address 0x10.  This makes sense as there are 4x 4 byte addresses (stack pointer, reset vector, NMI vector, Hard Fault vector)</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.34.19-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.34.19-PM.png" alt="PSoC4 Boot Sequence: Linker Map File" width="2112" height="1006" class="alignnone wp-image-3051 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.34.19-PM.png 2112w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.34.19-PM-600x286.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.34.19-PM-300x143.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.34.19-PM-768x366.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-1.34.19-PM-1024x488.png 1024w" sizes="(max-width: 2112px) 100vw, 2112px" /></a></p>
<p>And the stack landed at 0x200038000 and ends at 0x20004000 which makes sense as we have 16K of SRAM aka 0x4000 bytes.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.11.23-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.11.23-PM.png" alt="PSoC4 Boot Sequence: Linker Map for Stack" width="1168" height="112" class="alignnone wp-image-3056 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.11.23-PM.png 1168w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.11.23-PM-600x58.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.11.23-PM-300x29.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.11.23-PM-768x74.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-04-at-2.11.23-PM-1024x98.png 1024w" sizes="(max-width: 1168px) 100vw, 1168px" /></a></p>
<p>In the next post we will follow through the &#8220;Reset()&#8221; function and the initialization of the BSS&amp;Data section as well as the C-Standard library.</p>
<p><span><p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >Article</th>
<th >Description</th>
</tr>
</thead>
<tbody>
<tr><td ><a href="https://iotexpert.com/2017/04/14/psoc4-boot-sequence-part-1-debugging-to-the-reset-vector/" target="_blank" rel="noopener noreferrer">PSoC4 Boot Sequence (Part 1) - Debugging to the Reset Vector</a></td>
<td >An introduction to the PSoC4 Boot Sequence</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/04/18/psoc4-boot-sequence-part-2-creating-the-exception-table-using-the-linker/" target="_blank" rel="noopener noreferrer">PSoC4 Boot Sequence (Part 2) - Creating the Exception Table using the Linker</a></td>
<td >Building the exception vector table</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/04/21/psoc4-boot-sequence-part-3-preinitializing-variables-before-main/" target="_blank" rel="noopener noreferrer">PSoC4 Boot Sequence (Part 3) - Preinitializing Variables before main()</a></td>
<td >Initializing BSS and Data</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/04/24/psoc4-boot-sequence-part-4-linker-trickery-with-__attribute_constructor101/" target="_blank" rel="noopener noreferrer">PSoC4 Boot Sequence (Part 4) - Linker trickery with __attribute_((constructor(101)))</a></td>
<td >Running initialize_psoc()</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/05/02/psoc4-boot-sequence-part-5-initializing-the-psoc-with-initialize_psoc/">PSoC4 Boot Sequence (Part 5) - Initialize PSoC</a></td>
<td ></td>
</tr>
</tbody></table></div></p>
<p>&nbsp;</p></span></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/psoc4-boot-sequence-part-2-creating-the-exception-table-using-the-linker/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Particle Photon:  Elkhorn Creek Depth</title>
		<link>https://iotexpert.com/particle-photon-elkhorn-creek-depth/</link>
					<comments>https://iotexpert.com/particle-photon-elkhorn-creek-depth/#comments</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Thu, 30 Mar 2017 16:12:10 +0000</pubDate>
				<category><![CDATA[Particle]]></category>
		<category><![CDATA[Particle Photon]]></category>
		<category><![CDATA[Thing Speak]]></category>
		<category><![CDATA[WIFI]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=3296</guid>

					<description><![CDATA[Summary In the previous article I showed you all of the components of the Particle Photon Ecosystem.  All that is cool.  But what can you build?  I have written extensively about the Elkhorn Creek in my backyard, and the system that I built to monitor the water level.  As part of that series of articles I explained that [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>Summary</h1>
<p>In the previous article I showed you all of the components of the <a href="http://particle.io" target="_blank">Particle</a> Photon Ecosystem.  All that is cool.  But what can you build?  I have written extensively about the <a href="http://www.elkhorn-creek.org/creekServer/creekPlots/current.html" target="_blank">Elkhorn Creek</a> in my backyard, and the <a href="https://iotexpert.com/category/solutions/elkhorn-creek/" target="_blank">system</a> that I built to monitor the water level.  As part of that series of articles I explained that I have a 4-20ma current loop that turns pressure into water level read <a href="https://iotexpert.com/2016/01/25/the-elkhorn-creek/" target="_blank">here</a> .  In this article I will:</p>
<ul>
<li>Attach the Photon to my Creek System Current Loop</li>
<li>Write the Firmware in the Particle Cloud IDE to publish W</li>
<li>Send events to the Particle Cloud &amp; monitor</li>
<li>Use Webhooks to send the data to ThingSpeak.com</li>
</ul>
<h1>Attach Particle Photon to Creek System</h1>
<p>To interface to a 4-20mA current look you just attach it to a 51.1 ohm resistor to serve as a trans-impedence amplifier.  Here is the PSoC Creator schematic for the board:  Using this schematic, the system will generate a voltage between (51.1 Ohms * 4ma = 204.4mV) and (51.1Ohm * 20mA = 1022 mV).   This voltage can then be attached to an Analog To Digital Convertor, then converted digitally into a Pressure, then a water depth.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/02/creekOverallSchematic.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/02/creekOverallSchematic.png" alt="" width="902" height="666" class="alignnone size-full wp-image-553" srcset="https://iotexpert.com/wp-content/uploads/2016/02/creekOverallSchematic.png 902w, https://iotexpert.com/wp-content/uploads/2016/02/creekOverallSchematic-600x443.png 600w, https://iotexpert.com/wp-content/uploads/2016/02/creekOverallSchematic-300x222.png 300w" sizes="(max-width: 902px) 100vw, 902px" /></a></p>
<p>I decided that the easiest thing to do with the Particle Photon was to attach the pin A0 to the highside input.  This was easy as I put a loop on the <a href="https://iotexpert.com/2016/02/07/the-creek-board-1-1/" target="_blank">Creek Board</a>.  The loop is labeled &#8220;PRES&#8221;.  The picture is a bit ugly as I was standing in the dark in the rafters of my barn.  Sorry.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/IMG_3990.jpg"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/IMG_3990-e1490221901847.jpg" alt="Particle Photon attached to Elkhorn Creek Water Level 1.1" width="3024" height="4032" class="alignnone wp-image-3307 size-full" /></a></p>
<h1>Particle Photon Firmware</h1>
<p>When you look at the main loop of the firmware, lines 23-40 it does three things</p>
<ul>
<li>Reads the ADC voltage on Pin A0</li>
<li>Applies an Infinite Impulse Response Filter (IIR) with coefficients of 7/8 and 1/8.  This is low pass filter.</li>
<li>Turns the voltage into depth.  This is done by turning (4-20ma) into (0-15 psi) then PSI into Feet</li>
</ul>
<p>Then, on lines 34-39, I use the system time to figure out if it is time to publish again.  I publish every &#8220;INTERVAL&#8221;.</p>
<p>In order to test the Particle Cloud interface to the Photon, I setup all of the intermediate calculation of depth as &#8220;Particle.variable&#8221;s which allows me to inspect them remotely.</p>
<pre class="lang:c++ range:1-100 decode:true" title="Particle Photon Firmware">uint32_t nextTime; // when do you want to publish the data again
const uint32_t INTERVAL = (5*60*1000); // every 5 minutes in milliseconds
const double  MVPERCOUNT = (3330.0/4096.0); // 3300mv and 2^12 counts
uint32_t current;
uint32_t filter=0;
double depth;
double percent;
double psi;
double voltage;
double percentTemp;

void setup() {
    nextTime =  millis() + INTERVAL;
    // setup variables so that they can be polled
    Particle.variable("filter",filter);
    Particle.variable("adc",current);
    Particle.variable("percent",percent);
    Particle.variable("voltage",voltage);
    Particle.variable("psi",psi);
    Particle.variable("depth",depth);
}

void loop() {
   
   char buff[128];
   
    current = analogRead(A0);
    filter = ((filter&gt;&gt;3) * 7) + (current&gt;&gt;3); // IIR Filter with 7/8 and 1/8 coeffecients
    voltage  = ((double)filter) * MVPERCOUNT; // Convert ADC to Milivolts
    percent = ( voltage - (51.1*4.0) ) / (51.1 * (20.0-4.0)); // 51.1 ohm resistor... 4-20ma 
    psi = percent * 15.0; // Range of pressure sensor
    depth = psi / 0.53; // Magic 0.53psi per foot

   if(millis() &gt; nextTime)
   {
        sprintf(buff,"%.1f",depth);
        Particle.publish("CreekDepth",buff);
        nextTime = millis() + INTERVAL;
   }
}</pre>
<h1>Sending Events to the Particle Cloud &amp; Monitor</h1>
<p>Once I flashed the firmware with the very cool Over-The-Air Bootloader, I go to the Particle Console and click on my device.  As soon as I do that I see the &#8220;Particle.variable&#8221;s that I defined in the firmware.  One by one I press &#8220;get&#8221; and after a second the data is displayed on the screen.  I am not exactly sure how the exactly works, but it is cool.</p>
<h1><a href="https://iotexpert.com/wp-content/uploads/2017/03/consoleCloud.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/consoleCloud.png" alt="Particle Cloud Device Console" width="1500" height="790" class="alignnone wp-image-3308 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/consoleCloud.png 1500w, https://iotexpert.com/wp-content/uploads/2017/03/consoleCloud-600x316.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/consoleCloud-300x158.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/consoleCloud-768x404.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/consoleCloud-1024x539.png 1024w" sizes="(max-width: 1500px) 100vw, 1500px" /></a></h1>
<p>After inspecting the variables, I go the Logs page and look to see what the events are.  You can see that every 5 minutes (about) there is an event called &#8220;CreekDepth&#8221; with a -0.0 or so. That is good as it means that the Particle Photon is publishing regularly.  The answer is 0.0 (or about 0.0) as the Elkhorn Creek if not doing anything right now.  The other events are part of the web hook that I setup (and will talk about in the next section).</p>
<h1><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.46.47-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.46.47-PM.png" alt="Particle Cloud Device Event Log" width="1483" height="1136" class="alignnone wp-image-3309 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.46.47-PM.png 1483w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.46.47-PM-600x460.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.46.47-PM-300x230.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.46.47-PM-768x588.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.46.47-PM-1024x784.png 1024w" sizes="(max-width: 1483px) 100vw, 1483px" /></a></h1>
<h1>Using WebHooks to send data to ThingSpeak.com</h1>
<p>Unless I am missing something, the Particle Cloud does not store your actual data.  They do have a mechanism to take Events from your devices and trigger a &#8220;WebHook&#8221;.  This is basically a RESTFul API call to another cloud.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/webhooks-overview.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/webhooks-overview.png" alt="Particle Cloud Webhooks" width="800" height="431" class="alignnone size-full wp-image-3324" srcset="https://iotexpert.com/wp-content/uploads/2017/03/webhooks-overview.png 800w, https://iotexpert.com/wp-content/uploads/2017/03/webhooks-overview-600x323.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/webhooks-overview-300x162.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/webhooks-overview-768x414.png 768w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>They call these &#8220;integrations&#8221; and you configure them on the Console.  When you press &#8220;Integrations&#8221; you end up with this screen which gives you the option of editing a current webhook or creating a new one.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.00.05-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.00.05-AM.png" alt="Particle Cloud Integrations" width="1038" height="412" class="alignnone wp-image-3313 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.00.05-AM.png 1038w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.00.05-AM-600x238.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.00.05-AM-300x119.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.00.05-AM-768x305.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.00.05-AM-1024x406.png 1024w" sizes="(max-width: 1038px) 100vw, 1038px" /></a></p>
<p>When you click on &#8220;new integration&#8221; it gives you the option of connecting to Google, Microsoft Azure or Webhook.  I havent tried Google or Azure so for this article Ill stick with a Webhook.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-5.58.37-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-5.58.37-AM.png" alt="Particle Cloud New Integration" width="1104" height="365" class="alignnone wp-image-3312 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-5.58.37-AM.png 1104w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-5.58.37-AM-600x198.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-5.58.37-AM-300x99.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-5.58.37-AM-768x254.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-5.58.37-AM-1024x339.png 1024w" sizes="(max-width: 1104px) 100vw, 1104px" /></a></p>
<p>I started with a WebHook to the <a href="https://thingspeak.com" target="_blank">ThingSpeak</a> Cloud (because they show a nice <a href="https://docs.particle.io/guide/tools-and-features/webhooks/" target="_blank">example</a> in the documentation).  ThingSpeak is run by the <a href="https://www.mathworks.com" target="_blank">MathWorks</a> people (same as Matlab).  They call ThingSpeak &#8220;an open IoT with Matlab Analytics&#8221;.  OK sounds cool.  In order to use it to collect and display data I start by creating a new account.  Then I click on the &#8220;New Channel&#8221; button to create an &#8220;Elkhorn Creek Depth&#8221; channel.  On this screen I say that there will be only one field &#8220;CreekDepth&#8221;.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.21.36-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.21.36-AM.png" alt="ThingSpeak Create New Channel" width="663" height="551" class="alignnone wp-image-3314 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.21.36-AM.png 663w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.21.36-AM-600x499.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.21.36-AM-300x249.png 300w" sizes="(max-width: 663px) 100vw, 663px" /></a></p>
<p>In order to write data into this channel you need to have the API keys which give your Restful API call the authority to write into the database.  Press &#8220;API Keys&#8221; and you will see this screen.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/new-channel.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/new-channel.png" alt="ThingSpeak Channel API Keys" width="1355" height="1125" class="alignnone wp-image-3318 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/new-channel.png 1355w, https://iotexpert.com/wp-content/uploads/2017/03/new-channel-600x498.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/new-channel-300x249.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/new-channel-768x638.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/new-channel-1024x850.png 1024w" sizes="(max-width: 1355px) 100vw, 1355px" /></a></p>
<p>Now that I have an active channel (and I know the channel number and API write key) I go back to the Particle Cloud Integrations tab and create a Webhook.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/webhook.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/webhook.png" alt="Particle Cloud Edit Integration" width="1310" height="1125" class="alignnone wp-image-3316 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/webhook.png 1310w, https://iotexpert.com/wp-content/uploads/2017/03/webhook-600x515.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/webhook-300x258.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/webhook-768x660.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/webhook-1024x879.png 1024w" sizes="(max-width: 1310px) 100vw, 1310px" /></a></p>
<p>Each time the &#8220;CreekDepth&#8221; event occurs, the Particle Cloud will do an API call to the ThingSpeak cloud and insert the new data.  On the ThingSpeak Cloud there is a chart of the data, and a handy-dandy way to insert the chart into your webpage.  Here it is for the Elkhorn Creek showing the last 6 hours of data which is flat at the time of this writing, but maybe when you read this page it will be raining in Kentucky and you will see something interesting.</p>
<h1><iframe width="450" height="260" style="border: 1px solid #cccccc;" src="https://thingspeak.com/channels/246112/charts/1?bgcolor=%23ffffff&amp;color=%23d62020&amp;dynamic=true&amp;results=60&amp;type=line&amp;yaxismax=15&amp;yaxismin=0"></iframe></h1>
<p>I guess at this point I have a number of questions which I will leave to the future:</p>
<ul>
<li>Exactly what is the form of the request made to the ThingSpeak cloud?</li>
<li>What is the mapping between the event &#8211;&gt; API Request</li>
<li>What is the protocol for Particle.variables?</li>
<li>How does the Microsoft integration work?</li>
<li>How does the Google integration work?</li>
<li>How do I save power on the Photon?</li>
</ul>
<p>I suppose Ill leave these questions to future posts.  If you have other questions leave them as I comment and Ill take a crack at trying to figure them out.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/particle-photon-elkhorn-creek-depth/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Particle Photon:  An Overview of the Particle Ecosystem</title>
		<link>https://iotexpert.com/particle-photon/</link>
					<comments>https://iotexpert.com/particle-photon/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Thu, 23 Mar 2017 10:00:47 +0000</pubDate>
				<category><![CDATA[Particle Photon]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=3268</guid>

					<description><![CDATA[Summary Over the last few days I have spent some time with the Particle Photon and looking around at the Particle Cloud, the Development Kits, the Documentation and Development Tools.  Fundamentally, Particle has built a very ambitious end-to-end cloud development platform.  I think that they have everything necessary to built a complete IoT solution into your system. [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>Summary</h1>
<p>Over the last few days I have spent some time with the <a href="https://www.particle.io/products/hardware/photon-wifi-dev-kit" target="_blank">Particle Photon</a> and looking around at the Particle Cloud, the Development Kits, the Documentation and Development Tools.  Fundamentally, Particle has built a very ambitious end-to-end cloud development platform.  I think that they have everything necessary to built a complete IoT solution into your system.  Obviously, I like them because they use a <a href="http://www.cypress.com/products/ieee-80211-abgn-wlan-sdio-usb-and-mimo" target="_blank">Cypress 43362 WICED WiFi</a> chip as the core of their solution, but the rest is cool as well.  Particle also offers a cellular connectivity solution using <a href="https://www.u-blox.com/en/u-blox-products" target="_blank">uBlox</a>, but I didn&#8217;t try that.  In this article I will give you a brief introduction to all of the components of their ecosystem including:</p>
<ul>
<li>Particle Photon WiFi</li>
<li>Particle Photon Development Kits</li>
<li>Particle Photon Development Environment</li>
<li>Particle Photon Support Tools</li>
<li>Documentation</li>
<li>Particle Cloud Console</li>
</ul>
<p>To develop with Particle you write your firmware in C++ with an Arduino library clone (many/most? of the APIs and libraries that you know and love are ported into the system).  The libraries also include a bunch of APIs for transferring actions and data to/from the cloud.  Once you have written the firmware you can flash you board either directly through the USB port or through the Cloud over-the-air bootloader (which works great)</p>
<h1>Particle Photon WiFi</h1>
<p>Particle makes two modules, called <a href="https://store.particle.io/products/p0" target="_blank">P0</a> ($10) and <a href="https://store.particle.io/products/p1" target="_blank">P1</a>, ($12) which you can build into your system.  Both are FCC certified modules that use the Cypress 43362 WICED WiFi chip which is 2.4GHz 802.11a/b/g/n paired (unfortunately) with a STM MCU to run WICED &amp; the Photon Environment.  Both of the modules are PCB circuit boards with QFN style pads on the bottom that let you solder them into your system.  The P0 is smaller (11mm x 12mm) but needs an antenna, and P1 is a bit bigger (28mm x 20mm) but has a PCB Antenna and SMA connector.  Here is a picture which I borrowed from the Particle Website.  The P0 is on the right, the P1 is in the middle, then on the left is a development kit with the P0 soldered into it.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/photons-scaling.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/photons-scaling.png" alt="Particle Photon WiFi" width="1200" height="900" class="alignnone wp-image-3270 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/photons-scaling.png 1200w, https://iotexpert.com/wp-content/uploads/2017/03/photons-scaling-600x450.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/photons-scaling-300x225.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/photons-scaling-768x576.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/photons-scaling-1024x768.png 1024w" sizes="(max-width: 1200px) 100vw, 1200px" /></a></p>
<h1>Particle Photon Development Kits</h1>
<p>Photon makes essentially one basic <a href="https://store.particle.io/collections/photon" target="_blank">development board</a> (shown above on the left) as well as a bunch of different <a href="https://store.particle.io/collections/shields-and-kits" target="_blank">support boards and package deals</a>.  The basic development kit is $19 and has a Photon P0, an antenna, an SMA connector for an external antenna, two buttons (reset and setup), one user LED, a USB programming/power connector and 100 mil center pins with the P0 pins broken out.  One very cool feature of the board is that the breakout pins are castellated on the side of the board so that you could solder it directly into your product.</p>
<p>One of the boards that I ended up using was a (now obsolete) SparkFun kit that has a Photon P1 soldered into an Arduino footprint board:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/IMG_3988.jpg"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/IMG_3988.jpg" alt="Particle Photon WiFi - SparkFun RedBoard" width="4032" height="3024" class="alignnone wp-image-3274 size-full" /></a></p>
<p>Here is a screenshot of many of the <a href="https://store.particle.io/collections/shields-and-kits" target="_blank">development kit packages</a> you can buy directly from Photon:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.50.09-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.50.09-AM.png" alt="Particle Photon WiFi Development Kits" width="1082" height="1283" class="alignnone wp-image-3277 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.50.09-AM.png 1082w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.50.09-AM-600x711.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.50.09-AM-253x300.png 253w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.50.09-AM-768x911.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.50.09-AM-864x1024.png 864w" sizes="(max-width: 1082px) 100vw, 1082px" /></a></p>
<p>In addition there are several other makers of support boards including <a href="https://www.sparkfun.com/search/results?term=photon" target="_blank">SparkFun</a>, <a href="https://www.adafruit.com/?q=photon&amp;" target="_blank">Adafruit</a> and <a href="https://www.seeedstudio.com/s/photon.html" target="_blank">SeeedStudio</a>.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.38.39-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.38.39-AM.png" alt="SparkFun Photon Kits" width="1127" height="1060" class="alignnone wp-image-3272 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.38.39-AM.png 1127w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.38.39-AM-600x564.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.38.39-AM-300x282.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.38.39-AM-768x722.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.38.39-AM-1024x963.png 1024w" sizes="(max-width: 1127px) 100vw, 1127px" /></a></p>
<p><a href="https://www.adafruit.com/?q=photon&amp;" target="_blank">Adafruit</a>:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.41.14-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.41.14-AM.png" alt="AdaFruit Photon Kit" width="1026" height="241" class="alignnone wp-image-3273 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.41.14-AM.png 1026w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.41.14-AM-600x141.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.41.14-AM-300x70.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.41.14-AM-768x180.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.41.14-AM-1024x241.png 1024w" sizes="(max-width: 1026px) 100vw, 1026px" /></a></p>
<p><a href="https://www.seeedstudio.com/s/photon.html" target="_blank">SeeedStudio</a>:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.43.06-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.43.06-AM.png" alt="SeeedStudio Photon Kits" width="927" height="738" class="alignnone wp-image-3276 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.43.06-AM.png 927w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.43.06-AM-600x478.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.43.06-AM-300x239.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.43.06-AM-768x611.png 768w" sizes="(max-width: 927px) 100vw, 927px" /></a></p>
<h1>Particle Photon Development Environment</h1>
<p>Particle offers two integrated development environments, one web based and one computer client based on <a href="https://atom.io" target="_blank">Atom</a>.  Both are approximately Arduino clones&#8230; and both work very well.</p>
<p>The web based environment includes a code editor, compiler, over-the-air flash utility. and library utility.  Here is screenshot of one of the programs that I was working on.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.55.10-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.55.10-AM.png" alt="Particle Photon Cloud IDE" width="1042" height="862" class="alignnone wp-image-3280 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.55.10-AM.png 1042w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.55.10-AM-600x496.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.55.10-AM-300x248.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.55.10-AM-768x635.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.55.10-AM-1024x847.png 1024w" sizes="(max-width: 1042px) 100vw, 1042px" /></a>And the desktop environment, which works on Windows, Mac and Linux, is very well integrated and &#8220;feels&#8221; just like the web environment.  I was amazed that as soon as I installed the tool it was connected to the Particle Cloud and to my devices.  I created a very simple blink the led program.  After I pressed the lightning bolt&#8230; 15 seconds later my board was bootloaded over the air.  Here is a screenshot from my Mac.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-7.34.24-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-7.34.24-AM.png" alt="Particle Photon Desktop Client IDE" width="1052" height="718" class="alignnone wp-image-3282 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-7.34.24-AM.png 1052w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-7.34.24-AM-600x410.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-7.34.24-AM-300x205.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-7.34.24-AM-768x524.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-7.34.24-AM-1024x699.png 1024w" sizes="(max-width: 1052px) 100vw, 1052px" /></a></p>
<h1>Particle Photon Support Tools</h1>
<p>There are two sets of command line tools that you can use to interact with the Photons, dfu-util and the Particle-cli.</p>
<p>The first is &#8220;<a href="http://dfu-util.sourceforge.net" target="_blank">dfu-util</a>&#8221;  which I didn&#8217;t know anything about until I started using the Photons.  DFU-UTIL is a USB bootloader host that allows you to update sections of the Photons firmware.  When I took my boards out of the box they had very old system firmware and things were not connecting correctly.  I ended up having to download new system firmware and then install it on the boards.  The instructions were on <a href="https://docs.particle.io/support/troubleshooting/firmware-upgrades/photon/" target="_blank">this</a> website.</p>
<p>The second tool, called the <a href="https://docs.particle.io/guide/tools-and-features/cli/photon/" target="_blank">Particle Command Line Interface</a> is also really cool.   Once you install it you can upgrade firmware, send commands, read and write data, call functions etc on your devices.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-8.29.37-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-8.29.37-AM.png" alt="Particle Command Line Interface" width="537" height="369" class="alignnone wp-image-3286 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-8.29.37-AM.png 537w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-8.29.37-AM-300x206.png 300w" sizes="(max-width: 537px) 100vw, 537px" /></a></p>
<h1>Documentation</h1>
<p>The bottom line is the documentation is outstanding, something that is a rare and wonderful thing in the business.  You can find it on their <a href="https://docs.particle.io/guide/getting-started/intro/photon/" target="_blank">website</a>.  Here is a screenshot of the first page.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-11.07.19-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-11.07.19-AM.png" alt="Particle Photon Documentation" width="1027" height="751" class="alignnone wp-image-3288 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-11.07.19-AM.png 1027w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-11.07.19-AM-600x439.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-11.07.19-AM-300x219.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-11.07.19-AM-768x562.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-11.07.19-AM-1024x749.png 1024w" sizes="(max-width: 1027px) 100vw, 1027px" /></a></p>
<h1>Particle Cloud</h1>
<p>An IoT device isn&#8217;t worth much unless it is integrated with the cloud.  Particle provides a bunch of things in their cloud.  In addition they give you the ability to drive data and events into other clouds.  With the Particle Cloud you can</p>
<ol>
<li>From the cloud, read and write data from devices</li>
<li>Push and retrieve data from your device to the cloud</li>
<li>You can manage and provision devices</li>
<li>You can flash new firmware OTA to your devices</li>
</ol>
<p>There is a free tier for makers and experiments which includes up to about 25 devices and 250K transactions per month.  Beyond that they have several subscription levels.  In the screen shot below you can see my two devices (one called &#8220;Red-board&#8221; and one called &#8220;test1&#8221;).  With this interface I can query the device and run &#8220;functions&#8221; which are like remote procedure calls.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/console.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/console.png" alt="Particle Cloud" width="1500" height="882" class="alignnone wp-image-3290 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/console.png 1500w, https://iotexpert.com/wp-content/uploads/2017/03/console-600x353.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/console-300x176.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/console-768x452.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/console-1024x602.png 1024w" sizes="(max-width: 1500px) 100vw, 1500px" /></a></p>
<p>In the console log you can see all of the events pertaining to your device.  In the screenshot below you can see that I changed the state of the button a bunch of times on the &#8220;Red-board&#8221;.  You can also see where the &#8220;test1&#8221; board was reset and re-attached to the network.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-11.14.32-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-11.14.32-AM.png" alt="Particle Cloud" width="1279" height="754" class="alignnone wp-image-3291 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-11.14.32-AM.png 1279w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-11.14.32-AM-600x354.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-11.14.32-AM-300x177.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-11.14.32-AM-768x453.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-11.14.32-AM-1024x604.png 1024w" sizes="(max-width: 1279px) 100vw, 1279px" /></a></p>
<p>In the next Particle post I will make something&#8230;. what?  Im not sure yet.  But Ill think of something.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/particle-photon/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Embedded World 2017: PSoC Analog CoProcessor CapSense GUI</title>
		<link>https://iotexpert.com/embedded-world-2017-psoc-analog-coprocessor-capsense-gui/</link>
					<comments>https://iotexpert.com/embedded-world-2017-psoc-analog-coprocessor-capsense-gui/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Thu, 09 Mar 2017 22:18:22 +0000</pubDate>
				<category><![CDATA[Embedded World 2017]]></category>
		<category><![CDATA[PSoC Creator]]></category>
		<category><![CDATA[WIFI]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=3156</guid>

					<description><![CDATA[Summary I have been building up pieces of code that are going to allow me to show the PSoC Analog CoProcessor &#8211;&#62; WICED WiFi &#8211;&#62; Amazon IoT &#8211;&#62; WICED WiFi &#8211;&#62; Secret New Chip &#8211;&#62; Robot Arm.   In the previous two articles (part1, part2) I have shown you how to build most of the WICED firmware. [&#8230;]]]></description>
										<content:encoded><![CDATA[<h2>Summary</h2>
<p>I have been building up pieces of code that are going to allow me to show the <a href="http://www.cypress.com/products/psoc-analog-coprocessor" target="_blank">PSoC Analog CoProcessor</a> &#8211;&gt; <a href="http://www.cypress.com/products/ieee-80211-abgn-wlan-sdio-usb-and-mimo" target="_blank">WICED WiFi</a> &#8211;&gt; <a href="https://aws.amazon.com/iot/" target="_blank">Amazon IoT</a> &#8211;&gt; <a href="http://www.cypress.com/products/ieee-80211-abgn-wlan-sdio-usb-and-mimo" target="_blank">WICED WiFi</a> &#8211;&gt; Secret New Chip &#8211;&gt; Robot Arm.   In the previous two articles (<a href="https://iotexpert.com/2017/03/08/embedded-world-2017-wiced-wifi-mqtt-and-the-amazon-iot-cloud/">part1</a>, <a href="https://iotexpert.com/2017/03/09/embedded-world-2017-wiced-wifi-mqtt-and-the-amazon-iot-cloud-part-2/">part2</a>) I have shown you how to build most of the WICED firmware.  In this article I am going to focus on the PSoC Analog CoProcessor firmware (but if you look real close you can see the secret new chip&#8217;s development kit).</p>
<p>In the picture below you can see the red shield board.  This is a shield with the PSoC Analog CoProcessor plus a bunch of sensors that show the power of that chip.  The shield also includes 4x CapSense Buttons which I am going to use to set the position of the Robot Arm.  The PSoC will serve as a front end companion to the WICED WiFi Development Kit.  They will communicate via I2C with the PSoC acting as an I2C Slave and the WICED WiFi as a master.  Here is a picture of the all of parts minus Amazon.com&#8217;s cloud.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/IMG_3844.jpg"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/IMG_3844.jpg" alt="Embedded World 2017 Components" width="4032" height="3024" class="alignnone wp-image-3162 size-full" /></a></p>
<h2>PSoC Analog CoProcessor</h2>
<p>The PSoC Analog CoProcessor has the new Cypress CapSense block that gives you a bunch of new features, including enough measurement range to measure a capacitative humidity sensor (which you can see in the upper left hand part of the board).  For this demonstration I am just going to use the 4 CapSense buttons.  They will serve as the user interface for the Robot Arm.  The 4 buttons will set 4 different positions, 20%,40%,60%,80%.  I will be talking in much more detail about this shield in coming posts (later next month)</p>
<h2>PSoC Analog CoProcessor Schematic</h2>
<p>The PSoC Creator schematic is pretty straight forward.  I use the EZI2C slave to provide communication for the WICED board.  There are 4x LEDs that sit right next to the CapSense buttons,  and there are the 4x CapSense buttons.  The only slightly odd duck is the Bootloadable component which I use because when I designed the shield I did not put a programmer on it.  The BootLoadable allows me to me to load new firmware into the PSoC via the I2C interface.  Here is the PSoC Creator Schematic:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.12.36-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.12.36-PM.png" alt="PSoC Creator Schematic" width="1024" height="730" class="alignnone wp-image-3169 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.12.36-PM.png 1024w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.12.36-PM-600x428.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.12.36-PM-300x214.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.12.36-PM-768x548.png 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>The CapSense configuration just specifies the use of 4x CapSense buttons that are automatically tuned by the Cypress magic.</p>
<p><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.12.58-PM.png" alt="CapSense Configuration" width="1570" height="784" class="alignnone wp-image-3168 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.12.58-PM.png 1570w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.12.58-PM-600x300.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.12.58-PM-300x150.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.12.58-PM-768x384.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.12.58-PM-1024x511.png 1024w" sizes="(max-width: 1570px) 100vw, 1570px" /></p>
<p>The last step in configuring the schematic is to assign all of the pins to the correct locations.</p>
<p><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.13.36-PM.png" alt="Pin Assignment" width="1492" height="560" class="alignnone wp-image-3167 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.13.36-PM.png 1492w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.13.36-PM-600x225.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.13.36-PM-300x113.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.13.36-PM-768x288.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.13.36-PM-1024x384.png 1024w" sizes="(max-width: 1492px) 100vw, 1492px" /></p>
<h2>PSoC Analog CoProcessor Firmware</h2>
<p>One of the great things about all of this process is how easy the firmware is to write.</p>
<ul>
<li>Line 3 declares a buffer that will be used to relay the position information to the WICED board.  I start the position at 50%</li>
<li>Lines 8-9 start the EZI2C which starts up the EZI2C protocol and tells it to read from the &#8220;position&#8221; variable</li>
<li>Lines 10-11 gets the CapSense going</li>
</ul>
<p>Inside of the infinite while(1) loop, I read from the CapSense and do the right thing</p>
<ul>
<li>Lines 17-22 reads the CapSense status</li>
<li>Lines 24-27 set the correct position based on which buttons are pressed (notice that if no button is pressed then the position stays the same)</li>
<li>Line 29 turns on the Bootloader if B0 &amp; B3 are pressed</li>
</ul>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.59.13-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.59.13-PM.png" alt="PSoC Analog CoProcessor Main.c" width="1546" height="1160" class="alignnone wp-image-3174 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.59.13-PM.png 1546w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.59.13-PM-600x450.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.59.13-PM-300x225.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.59.13-PM-768x576.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-4.59.13-PM-1024x768.png 1024w" sizes="(max-width: 1546px) 100vw, 1546px" /></a></p>
<h2>Testing the PSoC Analog CoProcessor System</h2>
<p>The easiest way to test the system is to use the Bridge Control Panel which comes as part of the PSoC Creator installation.  It lets me read the value from the EZ2IC buffer to make sure that the CapSense buttons are doing the right thing.  The command language is pretty simple.  You can see in the editor window that I typed &#8220;W42 0 R 42 X p;&#8221;  Everytime I press &#8220;enter&#8221; it sends the I2C commands:</p>
<ul>
<li>Send an I2C start</li>
<li>write the 7-bit I2C address 0x42</li>
<li>write a 0</li>
<li>send a restart</li>
<li>read from address 0x42</li>
<li>read one byte</li>
<li>send a stop</li>
</ul>
<p>You can see that I pressed each button and indeed got 20,40,60,80 (assuming you can convert hex to decimal&#8230; but trust me)</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-5.01.29-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-5.01.29-PM.png" alt="Bridge Control Panel" width="1866" height="1354" class="alignnone wp-image-3175 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-5.01.29-PM.png 1866w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-5.01.29-PM-600x435.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-5.01.29-PM-300x218.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-5.01.29-PM-768x557.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-09-at-5.01.29-PM-1024x743.png 1024w" sizes="(max-width: 1866px) 100vw, 1866px" /></a></p>
<p>In the next article I will modify the WICED Publisher to poll the PSoC Analog CoProcessor and then publish the current state.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/embedded-world-2017-psoc-analog-coprocessor-capsense-gui/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>ThingSoC PSoC4L: Using &#038; Debugging the PSoC4 Clock</title>
		<link>https://iotexpert.com/thingsoc4l-using-debugging-the-psoc4-clock/</link>
					<comments>https://iotexpert.com/thingsoc4l-using-debugging-the-psoc4-clock/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Mon, 30 Jan 2017 11:00:12 +0000</pubDate>
				<category><![CDATA[PSoC 4200]]></category>
		<category><![CDATA[ThingSoC]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=2733</guid>

					<description><![CDATA[Pattern Agents are running a crowd funding effort for TSoC &#8230; here Summary In the previous post I told you that I immediately blew away the factory firmware on the TSoC4L board.  I&#8217;m like that sometimes :-).  In this post I am going to take you through the entire process of getting and reprogramming the [&#8230;]]]></description>
										<content:encoded><![CDATA[<h4><span style="color: #ff0000;"><span style="color: #008000;">Pattern Agents are running a crowd funding effort for TSoC &#8230;</span> <a href="https://www.crowdsupply.com/patternagents-llc/thingsoc-grovey?utm_source=thingSOC+Supporters&amp;utm_campaign=f1c4185485-launch_thingsoc_2017_01_23&amp;utm_medium=email&amp;utm_term=0_4aec98a7fc-f1c4185485-112421013" target="_blank" style="color: #ff0000;">here</a></span></h4>
<h2>Summary</h2>
<p>In the previous post I told you that I immediately blew away the factory firmware on the TSoC4L board.  I&#8217;m like that sometimes :-).  In this post I am going to take you through the entire process of getting and reprogramming the factory firmware, then finding and debugging a PSoC4 clock problem.  The rest of this post is:</p>
<ol>
<li>Getting the correct firmware back on the TSoC4L Board</li>
<li>Running into a bug in the beta version of the firmware</li>
<li>Using the debugger to find the bug</li>
<li>Explaining the functionality of Low Frequency Clocks and the Watch Dog Timer</li>
<li>The Pattern Agents bug fix</li>
</ol>
<h2>Factory Firmware</h2>
<p>Getting things going again starts with &#8220;git&#8221;ing the firmware.  This can be done by &#8220;git clone git@github.com:PatternAgents/TSOC_PSoC4L.git&#8221;.  Once you have the repo cloned you will find a bunch of good stuff including:</p>
<ol>
<li>datasheets: All the datasheets</li>
<li>documentation: The PatternAgents documentation (quick start)</li>
<li>drivers: The windows USB &lt;-&gt; UART drivers</li>
<li>eagleUp: JPG renderings of the PCB</li>
<li>firmware: The PSoC Creator Project</li>
<li>hardware: gerbers, boms etc</li>
<li>images: renderings of the board, photos of the board etc</li>
<li>revisions: old revisions of the Eagle project files</li>
<li>The Eagle PCB Project including schematic and layout</li>
</ol>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-1.19.40-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-1.19.40-PM.png" alt="TSoC4 L Files from GitHub" width="677" height="289" class="alignnone wp-image-2747 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-1.19.40-PM.png 677w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-1.19.40-PM-600x256.png 600w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-1.19.40-PM-300x128.png 300w" sizes="(max-width: 677px) 100vw, 677px" /></a></p>
<p>When you open the PSoC Creator Workspace you will find two projects</p>
<ol>
<li>A USB Bootloader &#8211; called &#8220;USBFS_Bootloader&#8221;</li>
<li>The TSoC RSVP Firmware &#8211; called &#8220;rspvsis_4l_typ&#8221;</li>
</ol>
<p>The system is supposed to</p>
<ol>
<li>Start the USB HID bootloader (so you could get new firmware).  Wait for 10 seconds for a <a href="https://iotexpert.com/?s=bootloader" target="_blank">bootloader</a> host to start then if it doesnt &#8230; then start</li>
<li>The RSVP Firmware</li>
</ol>
<p>When you plug in the board you will see the TSoC4L enumerate as &#8220;Cypress ThingSoc Bootloader&#8221;.  Then, after 10 seconds, you should see it reboot, then enumerate as &#8220;Cypress USB UART&#8221;.  But, this was not happening for me.  Why?  I wasn&#8217;t sure.  The first thing that I did was add a blinking LED circuit that looked like this:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-6.34.18-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-6.34.18-AM.png" alt="Blinking LED" width="491" height="129" class="alignnone size-full wp-image-2753" srcset="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-6.34.18-AM.png 491w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-6.34.18-AM-300x79.png 300w" sizes="(max-width: 491px) 100vw, 491px" /></a></p>
<p>But the LED was not blinking.  That meant that the firmware was not even getting to main i.e. it was hanging BEFORE main in the PSoC boot code.  But where and why?</p>
<h2>Using the Debugger to Find the Bug</h2>
<p>How do you figure out where the system is stuck if you can&#8217;t even use the &#8220;blinking LED&#8221; or &#8220;printf&#8221; debug?  Simple.  Use the debugger.  Start by programming the PSoC with your firmware.  Then click &#8220;Debug-&gt;Attach to running target&#8221;.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-6.39.48-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-6.39.48-AM.png" alt="Starting the PSoC Debugger" width="584" height="313" class="alignnone wp-image-2754 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-6.39.48-AM.png 584w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-6.39.48-AM-300x161.png 300w" sizes="(max-width: 584px) 100vw, 584px" /></a></p>
<p>The debugger will start.  Then you will be able to press the &#8220;Pause&#8221; button. which will take you to a screen that looks like this:</p>
<p><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-6.21.22-AM.png" alt="PSoC4 Clock Busy Wait Loop" width="1184" height="623" class="alignnone wp-image-2738 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-6.21.22-AM.png 1184w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-6.21.22-AM-600x316.png 600w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-6.21.22-AM-300x158.png 300w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-6.21.22-AM-768x404.png 768w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-6.21.22-AM-1024x539.png 1024w" sizes="(max-width: 1184px) 100vw, 1184px" /></p>
<p>The chip is stuck on line 234.  What does line 234 do?  That is a busy wait loop.  It is waiting for the Watch Dog Control Register to clear.  To explain that, I will need to take you through the PSoC4 Low Frequency Clocks.  First you should notice that the file we are in is named &#8220;cyfitter_cfg.c&#8221;.  What is this file?  If you look at the top, this is what PSoC Creator says.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-6.56.40-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-6.56.40-AM.png" alt="" width="841" height="174" class="alignnone size-full wp-image-2757" srcset="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-6.56.40-AM.png 841w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-6.56.40-AM-600x124.png 600w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-6.56.40-AM-300x62.png 300w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-6.56.40-AM-768x159.png 768w" sizes="(max-width: 841px) 100vw, 841px" /></a></p>
<p>This means that the &#8220;cyfitter_cfg.c&#8221; file is synthesized by PSoC Creator when you do a build based on what you configured when you setup your project.  This file contains a bunch of the startup code including the code that gets the clock systems going.  Line 234 is inside of a function called &#8220;ClockSetup&#8221;.  All of this code is called BEFORE you get to main().</p>
<h2>The PSoC4 Clock(s)</h2>
<p>To explain why we are stuck there you first need to double click on the &#8220;Clocks&#8221; tab in the Design Wide Resources.  When you do that it will take you to this screen which contains a bunch of information about the clocking system in the PSoC.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-10.05.41-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-10.05.41-AM.png" alt="PSoC4 Clock Setup" width="1224" height="816" class="alignnone wp-image-2745 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-10.05.41-AM.png 1224w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-10.05.41-AM-600x400.png 600w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-10.05.41-AM-300x200.png 300w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-10.05.41-AM-768x512.png 768w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-10.05.41-AM-1024x683.png 1024w" sizes="(max-width: 1224px) 100vw, 1224px" /></a></p>
<p>In the screen above, you can see that there are three Timers in the Watch Dog Timer system (WDT) that are clocked (i.e. have a Source Clock of) by the Low Frequency Clock (LFCLK).  The LFCLK has its source as the Watch Crystal Oscillator (WCO).  If you double click the WCO line it will take you to a screen that is much easier to see what is going on, specifically the &#8220;Configure System Clocks&#8221; screen:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-6.22.50-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-6.22.50-AM.png" alt="PSoC4 Clock - Low Frequency" width="794" height="595" class="alignnone wp-image-2734 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-6.22.50-AM.png 794w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-6.22.50-AM-600x450.png 600w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-6.22.50-AM-300x225.png 300w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-6.22.50-AM-768x576.png 768w" sizes="(max-width: 794px) 100vw, 794px" /></a></p>
<p>In the screen above you can see that the LFCLK has two choices of oscillator sources, the &#8220;ILO&#8221; or the &#8220;WCO&#8221;.  ILO stands for Internal Low Speed Oscillator.  The ILO is a fairly inaccurate (+- 60%) RC oscillator that is built inside of the chip.   It is designed to be very low power which is why it is so inaccurate.  If you need a more accurate oscillator, then you should use an external oscillator, specifically a Watch Crystal Oscillator or WCO.  A WCO is a 32.768KHz crystal oscillator.  These watch crystal oscillators give you very precise clocks that can be used to drive real time clocks accurately.</p>
<p>The next thing to see is there are three Watch Dog Timers (WDT) numbered 0-2.  These times are driven by the &#8220;LFCLK&#8221;.  Here is a picture from the <a href="http://www.cypress.com/file/126171/download" target="_blank">PSoC Technical Reference Manual</a>.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-8.44.50-AM.png"><br />
</a><a href="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-8.44.50-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-8.44.50-AM.png" alt="PSoC4 Clock - WDT Block Diagram" width="1936" height="954" class="alignnone wp-image-2742 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-8.44.50-AM.png 1936w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-8.44.50-AM-600x296.png 600w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-8.44.50-AM-300x148.png 300w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-8.44.50-AM-768x378.png 768w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-8.44.50-AM-1024x505.png 1024w" sizes="(max-width: 1936px) 100vw, 1936px" /></a></p>
<p>So what is the &#8220;CYREG_WDT_CONTROL&#8221;?  You can find that by looking in the <a href="http://www.cypress.com/file/122336/download" target="_blank">PSoC4 Registers TRM</a>.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-8.43.23-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-8.43.23-AM.png" alt="PSoC4 Clock WDT Control Register" width="1444" height="1374" class="alignnone wp-image-2743 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-8.43.23-AM.png 1444w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-8.43.23-AM-600x571.png 600w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-8.43.23-AM-300x285.png 300w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-8.43.23-AM-768x731.png 768w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-23-at-8.43.23-AM-1024x974.png 1024w" sizes="(max-width: 1444px) 100vw, 1444px" /></a></p>
<p>The busy wait loop is waiting for bits 19,11,3 to be cleared.  Those bits are &#8220;WDT_RESETx&#8221;  They become 0 when the three WDT timers are cleared which happens &#8220;several LFCLK cycles&#8221; after the reset.  As a reminder, here is that block of code:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-7.31.22-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-7.31.22-AM.png" alt="" width="623" height="20" class="alignnone size-full wp-image-2763" srcset="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-7.31.22-AM.png 623w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-7.31.22-AM-600x19.png 600w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-7.31.22-AM-300x10.png 300w" sizes="(max-width: 623px) 100vw, 623px" /></a></p>
<p>This still leaves us with the question, &#8220;What is the problem?&#8221;.  If you look on the back of the ThingSoC4L board you will see there is no Crystal populated on this board. (the blank footprint on the right side of the back).  The WCO is an optional feature from Pattern Agents.  If you need the more accurate timing, you need to solder on your own Crystal.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/IMG_3637.jpg"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/IMG_3637.jpg" alt="Backside of ThingSoC4L PCB" width="4032" height="3024" class="alignnone wp-image-2759 size-full" /></a></p>
<p>If there is no WCO crystal, then the WDT timer reset will never happen because LFCLK isn&#8217;t doing anything.  And, the busy wait loop will never end.  Mystery solved.</p>
<h2>The Pattern Agents Bug Fix</h2>
<p>To fix the startup problem, the Pattern Agents guys changed the clock configuration to</p>
<ol>
<li>Turn off the WDTs</li>
<li>Use the ILO as the source of the LFCLK</li>
</ol>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-7.34.07-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-7.34.07-AM.png" alt="PSoC4 Clock - Low Frequency Setup" width="795" height="595" class="alignnone wp-image-2764 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-7.34.07-AM.png 795w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-7.34.07-AM-600x449.png 600w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-7.34.07-AM-300x225.png 300w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-24-at-7.34.07-AM-768x575.png 768w" sizes="(max-width: 795px) 100vw, 795px" /></a></p>
<p><span><p>You can find all of the projects in the TSoC Series at my GitHub ThingSoC repository git@github.com:iotexpert/ThingSoC.git</p>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >Index</th>
<th >Description</th>
</tr>
</thead>
<tbody>
<tr><td ><a href="https://iotexpert.com/2017/01/25/thingsoc-psoc4l/">ThingSoc: TSoC PSoC4L Development Kit from PatternAgents</a></td>
<td >Introduction to ThingSoC</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/01/30/thingsoc4l-using-debugging-the-psoc4-clock/" target="_blank">ThingSoC PSoC4L: Using &amp; Debugging the PSoC4 Clock</a></td>
<td >Debugging a beta firmware problem</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/02/02/thingsoc-tsoc-grovey-i2chub-i2c-hubswitch/" target="_blank">ThingSoC: The TSoC GROVEY I2CHUB : I2C Hub/Switch</td>
<td >Evaluating the ThingSoC I2C Hub</a></td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/02/06/thingsoc-psoc4l-i2c-oled-displays/" target="_blank">ThingSoC: Multiple I2C Displays</td>
<td >Using the I2CHUB and U8X8 Library</a></td>
<td >A project using ThingSoC I2C Hub &amp; 4 OLED Displays</td>
</tr>
</tbody></table></div></p></span></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/thingsoc4l-using-debugging-the-psoc4-clock/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>The Creek: Creek Server 1.2</title>
		<link>https://iotexpert.com/the-creek-creek-server-1-2/</link>
					<comments>https://iotexpert.com/the-creek-creek-server-1-2/#comments</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Sun, 28 Aug 2016 09:00:41 +0000</pubDate>
				<category><![CDATA[Elkhorn Creek]]></category>
		<category><![CDATA[Solutions]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=1390</guid>

					<description><![CDATA[In the previous post, I talked about two problems that I had discovered in my system.  I addressed first one,  a serious bug in the data collection, last time.  In this post Ill address the slow performance of the website.  A common way to solve a performance problem is with a cache.  Instead of running [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In the previous post, I talked about two problems that I had discovered in my system.  I addressed first one,  a serious bug in the data collection, last time.  In this post Ill address the slow performance of the website.  A common way to solve a performance problem is with a cache.  Instead of running the web page charts in real time, I will create them automatically every couple of minutes, then serve up a cached version.   In some ways this kind of sucks.  If I had known that I was going to go this way then there would have been 0 need of Tomcat and the Java Server Pages.  Oh well.</p>
<p>I start this process by copying the CreekHistory java object into the &#8220;getCreek&#8221; part of my project.  I then modify the main batch Java program, called &#8220;CreekServer&#8221; to understand the CreekHistory object.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-05-08-at-11.19.48-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-05-08-at-11.19.48-AM.png" alt="Screen Shot 2016-05-08 at 11.19.48 AM" width="591" height="144" class="alignnone size-full wp-image-1393" srcset="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-05-08-at-11.19.48-AM.png 591w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-05-08-at-11.19.48-AM-300x73.png 300w" sizes="(max-width: 591px) 100vw, 591px" /></a></p>
<p>Then I add a new function &#8220;createHtml&#8221; to the CreekHistory object.  This function creates the webpage with the current information on it.  Basically</p>
<ol>
<li>A table of the last three hours [line 221-235]</li>
<li>Link to the current chart [line 237]</li>
<li>Link to the floods charts [line 237/238]</li>
</ol>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-05-08-at-11.26.31-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-05-08-at-11.26.31-AM.png" alt="Screen Shot 2016-05-08 at 11.26.31 AM" width="967" height="566" class="alignnone size-full wp-image-1394" srcset="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-05-08-at-11.26.31-AM.png 967w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-05-08-at-11.26.31-AM-600x351.png 600w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-05-08-at-11.26.31-AM-300x176.png 300w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-05-08-at-11.26.31-AM-768x450.png 768w" sizes="(max-width: 967px) 100vw, 967px" /></a></p>
<p>I then add the &#8220;Current&#8221; command to the &#8220;runi2c&#8221; batch program.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-05-08-at-11.39.43-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-05-08-at-11.39.43-AM.png" alt="Screen Shot 2016-05-08 at 11.39.43 AM" width="700" height="195" class="alignnone size-full wp-image-1396" srcset="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-05-08-at-11.39.43-AM.png 700w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-05-08-at-11.39.43-AM-600x167.png 600w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-05-08-at-11.39.43-AM-300x84.png 300w" sizes="(max-width: 700px) 100vw, 700px" /></a></p>
<p>This program is run every 2 minutes by the crontab on the Raspberry Pi.  I picked 2 minutes because that is a good bit longer than each job takes to run in total.   Notice that I check to see if the jobs are already running and quit the &#8220;runi2c&#8221; job if the chart creation process is already going on.</p>
<p>At this point I have (at least) several things which are ugly</p>
<ol>
<li>I don&#8217;t have a good back up system</li>
<li>I duplicate the &#8220;CreekHistory&#8221; object in the JSP as well as the &#8220;getCreek&#8221;</li>
<li>I duplicate the &#8220;readProperties&#8221; method into a bunch of different objects</li>
<li>I have 5Vs (I think) on the I2C pins of the Raspberry Pi, which I don&#8217;t understand why this isn&#8217;t a problem</li>
<li>I need to get the PSoC4 Bootloader Host going on the Raspberry Pi</li>
</ol>
<p><span><p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >Index</th>
<th >Description</th>
</tr>
</thead>
<tbody>
<tr><td ><a class="row-title" href="https://iotexpert.com/2016/01/25/the-elkhorn-creek/" title="Edit “The Creek: IOT for the Elkhorn Creek”">The Creek: IOT for the Elkhorn Creek</a></td>
<td >Introduction</td>
</tr>

<tr><td ><a class="row-title" href="https://iotexpert.com/2016/01/30/creek-architecture-1-0/" title="Edit “The Creek: Solution Architecture 1.0”">The Creek: Solution Architecture 1.0</a></td>
<td >Overall architecture</td>
</tr>

<tr><td ><a class="row-title" href="https://iotexpert.com/2016/02/07/the-creek-board-1-1/" title="Edit “The Creek: Creek Board 1.1”">The Creek: Creek Board 1.1</a></td>
<td >Eagle layout of the board</td>
</tr>

<tr><td ><a class="row-title" href="https://iotexpert.com/2016/02/14/creek-board-1-0-rcca/" title="Edit “The Creek: Creek Board 1.0 – RCCA”">The Creek: Creek Board 1.0 – RCCA</a></td>
<td >A discussion of the errors in the 1.0 board</td>
</tr>

<tr><td ><a class="row-title" href="https://iotexpert.com/2016/02/21/cypi/" title="Edit “The Creek: CYPI</td>
<td > a Raspberry Pi to Arduino Bridge”">The Creek: CYPI, a Raspberry Pi to Arduino Bridge</a></td>
<td > PSoC4 &lt;--&gt; Raspberry Pi Bridge Board</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/03/26/the-creek-psoc-4-creator-schematic-firmware/">The Creek: PSoC4 Creator Schematic and Firmware</a></td>
<td > Firmware to interface with the temperature and pressure sensors</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/04/10/the-creek-testing-the-firmware-2/">The Creek: Testing the Firmware</a></td>
<td > Using tools to verify that the PSoC 4 Firmware is working correctly</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/04/17/the-creek-testing-the-firmware/">The Creek: Testing the Bootloader</a></td>
<td > Make sure that you can load new firmware into the PSoC</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/04/24/the-creek-server-software-architecture/">The Creek: Software Architecture</a></td>
<td >All of the Raspberry Pi software connections</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/06/19/the-creek-install-mysql/">The Creek: Install MySql</a></td>
<td >Instruction to configure MySql</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/07/10/the-creek-install-tomcat/">The Creek: Install Tomcat</a></td>
<td >Instruction to configure Tomcat JSP Server</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/06/26/the-creek-collect-data-part-1/">The Creek: Data Collection Java (Part 1)</a></td>
<td >The Java program that reads the I2C and saves it in the database</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/07/03/the-creek-collect-data-part-2/">The Creek: Data Collection Java (Part 2)</a></td>
<td >The Java program that reads the I2C and saves it in the database</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/07/17/the-creek-create-the-chart-with-jfreechart/">The Creek: Create the Chart with JFreeChart</a></td>
<td >Using open source Java charting software to create plots of the Creek Depth</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/07/31/the-creek-flood-event-data-processor/">The Creek: Flood Event Data Processor</a></td>
<td >A batch program to create analyze the database and create a table of flood events</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/07/31/the-creek-flood-event-web-page/">The Creek: Flood Event Web Page</a></td>
<td > A batch program to create the flood event web page</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/08/07/the-creek-creek-server-1-1/">The Creek: Creek Server 1.1</a></td>
<td >Updates to all of the back off server programs to integrate charts</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/08/14/the-creek-web-pages-with-java-server-pages-jsp/">The Creek: JSP Web Page for www.elkhorn-creek.org</a></td>
<td >The JSP program to make the table and display the website</td>
</tr>

<tr><td >The Creek: Raspberry Pi Clock Stretching</td>
<td >Sorting out a bug in the system having to do with the Broadcomm Raspberry Pi Master not functioning well with clock stretching</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/08/28/the-creek-creek-server-1-2/">The Creek: Creek Server 1.2</a></td>
<td >Caching the web pages to make them faster</td>
</tr>
</tbody></table></div></p> </span></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/the-creek-creek-server-1-2/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>WICED WiFI</title>
		<link>https://iotexpert.com/wiced-wifi/</link>
					<comments>https://iotexpert.com/wiced-wifi/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Mon, 22 Aug 2016 15:45:32 +0000</pubDate>
				<category><![CDATA[Bluetooth]]></category>
		<category><![CDATA[WICED]]></category>
		<category><![CDATA[WIFI]]></category>
		<category><![CDATA[Zigbee]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=1847</guid>

					<description><![CDATA[Last week I had the supreme privilege of hosting the WICED WiFI + Bluetooth + Zigbee software team at my office in Kentucky. This included the overall manager for WICED software (a truly remarkable guy), the engineering managers for WiFI and Bluetooth, the head of applications for WICED as well as a bunch of the firmware [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Last week I had the supreme privilege of hosting the WICED WiFI + Bluetooth + Zigbee software team at my office in Kentucky. This included the overall manager for WICED software (a truly remarkable guy), the engineering managers for WiFI and Bluetooth, the head of applications for WICED as well as a bunch of the firmware guys.  It occurred to me during the week that the people joining Cypress was the best part of the Broadcomm IOT acquisition.  And that is saying something as I really like the products.  Also at the summit were all of the software engineering leaders for PSoC (who I have worked with closely all of my career).  Needless to say, it was a bunch of badass developers.</p>
<p>The purpose of the meeting was to introduce the PSoC team to WICED and then talk about the future roadmap for those products.  Obviously I can&#8217;t talk to much about the 2nd part&#8230; well actually the only thing I can say is that it will be amazing as we will be able to offer PSoC with the power of WICED.</p>
<p>What I can talk about is the first part.  So, I thought that I would show you one of the things that we did with WICED.  First of all, <a href="http://www.cypress.com/internet-things-iot" target="_blank">WICED</a> (Wireless Internet Connectivity for Embedded Devices) is the brand name that Cypress uses to describe all of the WiFi, Zigbee and Bluetooth <a href="http://www.cypress.com/products/wireless-connectivity" target="_blank">chips and modules</a> that were acquired from Broadcom/Avago.  The other thing we call WICED is the <a href="https://community.cypress.com/community/wiced-wifi/wiced-wifi-documentation" target="_blank">WICED SDK</a> which is used to mean <a href="http://www.eclipse.org" target="_blank">Eclipse</a> plus all of the tools (programer, plugins etc) plus the software library that is used to build products using the WICED chips and modules.</p>
<p>In the world of programming the first example is always &#8220;hello world&#8221;.  In the world of MCUs the first example is always &#8220;blinking led&#8221;.  It turns out that the first example in WiFi is &#8220;scan&#8221; to show that you can see all of the WiFi networks around you.   The purpose of all of these examples is to prove that all of the tools can do their thing.</p>
<p>To start with they gave me this devkit, the BCM94343WWCD1_1  <a href="https://iotexpert.com/wp-content/uploads/2016/08/IMG_3049.jpg"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/08/IMG_3049-1024x768.jpg" alt="IMG_3049" width="1024" height="768" class="alignnone size-large wp-image-1862" srcset="https://iotexpert.com/wp-content/uploads/2016/08/IMG_3049-1024x768.jpg 1024w, https://iotexpert.com/wp-content/uploads/2016/08/IMG_3049-300x225.jpg 300w, https://iotexpert.com/wp-content/uploads/2016/08/IMG_3049-768x576.jpg 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>The first thing to do is install <a href="https://community.cypress.com/docs/DOC-3123" target="_blank">WICED 3.7</a>.  When you start WICED you will see a screen like this:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.22.06-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.22.06-AM-1024x565.png" alt="Screen Shot 2016-08-22 at 8.22.06 AM" width="1024" height="565" class="alignnone size-large wp-image-1852" srcset="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.22.06-AM-1024x565.png 1024w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.22.06-AM-600x331.png 600w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.22.06-AM-300x166.png 300w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.22.06-AM-768x424.png 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>For the purposes of the first design there are two important things to see on this screen.  First on the left side is the project explorer.  It has all of the guts of WICED.  As part of the installation we provide you a bunch of &#8220;apps&#8221;.  These apps range from simple examples (in the snip folder) to full fledged production quality applications (in the demo folder)</p>
<ul>
<li>demo &#8211; full fledged applications</li>
<li>snip &#8211; short example projects</li>
<li>test &#8211; tools for debugging and testing wifi</li>
<li>waf &#8211; WICED Application Framework support (like an OTA Bootloader)</li>
<li>wwd &#8211; low level driver examples</li>
</ul>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.27.04-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.27.04-AM-596x1024.png" alt="Screen Shot 2016-08-22 at 8.27.04 AM" width="596" height="1024" class="alignnone size-large wp-image-1854" srcset="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.27.04-AM-596x1024.png 596w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.27.04-AM-600x1031.png 600w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.27.04-AM-175x300.png 175w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.27.04-AM-768x1320.png 768w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.27.04-AM.png 804w" sizes="(max-width: 596px) 100vw, 596px" /></a></p>
<p>The example that I want to build is &#8220;scan&#8221;  specifically &#8220;scan.c&#8221;.  That can be found in the apps/snip/scan folder.  In this screenshot you can see that I opened &#8220;scan.c&#8221;</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.43.49-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.43.49-AM-1024x572.png" alt="Screen Shot 2016-08-22 at 8.43.49 AM" width="1024" height="572" class="alignnone size-large wp-image-1857" srcset="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.43.49-AM-1024x572.png 1024w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.43.49-AM-600x335.png 600w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.43.49-AM-300x168.png 300w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.43.49-AM-768x429.png 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>The next thing that you need to do is build a &#8220;make target&#8221;.  The WICED team built a makefile that can seemingly do everything.  The makefile uses the name of the make target to setup all of the options required to do the make.  If you look on the right side of the screen you can see the currently existing targets:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.24.40-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.24.40-AM.png" alt="Screen Shot 2016-08-22 at 8.24.40 AM" width="784" height="556" class="alignnone size-full wp-image-1853" srcset="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.24.40-AM.png 784w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.24.40-AM-600x426.png 600w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.24.40-AM-300x213.png 300w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-8.24.40-AM-768x545.png 768w" sizes="(max-width: 784px) 100vw, 784px" /></a></p>
<p>The easiest way to make a new target is to copy/paste a currently existing target.  Then you can right click on the new target and edit it to get things setup correctly.  The target name defines:</p>
<ul>
<li>snip &#8211; the directory</li>
<li>scan &#8211; the subdirectory will the files (scan.c and scan.mk)</li>
<li>BCM94343WWCD1 &#8211; the name of the devkit (you can see it on the picture of the devkit)</li>
<li>download run &#8211; instructions to go ahead a boatload and start the app running</li>
</ul>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-11.32.06-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-11.32.06-AM.png" alt="Screen Shot 2016-08-22 at 11.32.06 AM" width="472" height="403" class="alignnone size-full wp-image-1865" srcset="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-11.32.06-AM.png 472w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-11.32.06-AM-300x256.png 300w" sizes="(max-width: 472px) 100vw, 472px" /></a></p>
<p>Next, I plug in the devkit.  When it attachs, the devkit will enumerate as two USB devices</p>
<ul>
<li>WICED USB JTAG Port</li>
<li>A serial port (in this case on COM12)</li>
</ul>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-11.29.45-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-11.29.45-AM.png" alt="Screen Shot 2016-08-22 at 11.29.45 AM" width="522" height="451" class="alignnone size-full wp-image-1864" srcset="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-11.29.45-AM.png 522w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-11.29.45-AM-300x259.png 300w" sizes="(max-width: 522px) 100vw, 522px" /></a></p>
<p>After I plug in the kit I run <a href="http://www.putty.org" target="_blank">Putty</a> and attach to COM12 at 115200 baud</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-11.36.32-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-11.36.32-AM.png" alt="Screen Shot 2016-08-22 at 11.36.32 AM" width="468" height="445" class="alignnone size-full wp-image-1866" srcset="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-11.36.32-AM.png 468w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-11.36.32-AM-300x285.png 300w" sizes="(max-width: 468px) 100vw, 468px" /></a></p>
<p>And finally, double click the make target to build, download and run.  After it starts, the Putty screen fills up with all of the WiFI networks that are around me.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-11.30.39-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-11.30.39-AM.png" alt="Screen Shot 2016-08-22 at 11.30.39 AM" width="900" height="629" class="alignnone size-full wp-image-1863" srcset="https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-11.30.39-AM.png 900w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-11.30.39-AM-600x419.png 600w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-11.30.39-AM-300x210.png 300w, https://iotexpert.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-22-at-11.30.39-AM-768x537.png 768w" sizes="(max-width: 900px) 100vw, 900px" /></a></p>
<p>All of that was pretty easy to get going.  Next lets see if I can actually do something.  Last week I showed the guys the <a href="https://iotexpert.com/2016/01/25/the-elkhorn-creek/" target="_blank">Elkhorn Creek Water Level</a> monitoring project and I told them that by the end of this week I would put one of their devkits into that system, so the next several posts will be about that process. (I hope)</p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/wiced-wifi/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>CY8CKIT-021: Example 10 &#8212; The iOS App</title>
		<link>https://iotexpert.com/cy8ckit-021-example-10-the-ios-app/</link>
					<comments>https://iotexpert.com/cy8ckit-021-example-10-the-ios-app/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Mon, 13 Jun 2016 09:00:47 +0000</pubDate>
				<category><![CDATA[Cy8CKIT-021]]></category>
		<category><![CDATA[DevKits]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=1618</guid>

					<description><![CDATA[Now that we have completely tested PRoC and PSoC4200M firmware the next step is to build an iOS App called Example 10.  The Xcode project is available in the Xcode directory in the project directory at github.com/iotexpert/cy8ckit-021/ Ill try to build this App to be as simple as possible.   Here is what the (single) [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Now that we have completely tested PRoC and PSoC4200M firmware the next step is to build an iOS App called Example 10.  The Xcode project is available in the Xcode directory in the project directory at <a href="https://github.com/iotexpert/cy8ckit-021/" target="_blank">github.com/iotexpert/cy8ckit-021/</a></p>
<p>Ill try to build this App to be as simple as possible.   Here is what the (single) screen looks like in three different state (nothing pressed, button0 pressed, led0 on):</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/06/IMG_0027.jpg"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/06/IMG_0027-169x300.jpg" alt="IMG_0027" width="169" height="300" class="alignnone wp-image-1619 size-medium" srcset="https://iotexpert.com/wp-content/uploads/2016/06/IMG_0027-169x300.jpg 169w, https://iotexpert.com/wp-content/uploads/2016/06/IMG_0027-600x1065.jpg 600w, https://iotexpert.com/wp-content/uploads/2016/06/IMG_0027-577x1024.jpg 577w, https://iotexpert.com/wp-content/uploads/2016/06/IMG_0027.jpg 640w" sizes="(max-width: 169px) 100vw, 169px" /></a>     <a href="https://iotexpert.com/wp-content/uploads/2016/06/IMG_0028.jpg"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/06/IMG_0028-169x300.jpg" alt="IMG_0028" width="169" height="300" class="alignnone wp-image-1620 size-medium" srcset="https://iotexpert.com/wp-content/uploads/2016/06/IMG_0028-169x300.jpg 169w, https://iotexpert.com/wp-content/uploads/2016/06/IMG_0028-600x1065.jpg 600w, https://iotexpert.com/wp-content/uploads/2016/06/IMG_0028-577x1024.jpg 577w, https://iotexpert.com/wp-content/uploads/2016/06/IMG_0028.jpg 640w" sizes="(max-width: 169px) 100vw, 169px" /></a>    <a href="https://iotexpert.com/wp-content/uploads/2016/06/IMG_0029.jpg"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/06/IMG_0029-169x300.jpg" alt="IMG_0029" width="169" height="300" class="alignnone wp-image-1621 size-medium" srcset="https://iotexpert.com/wp-content/uploads/2016/06/IMG_0029-169x300.jpg 169w, https://iotexpert.com/wp-content/uploads/2016/06/IMG_0029-600x1065.jpg 600w, https://iotexpert.com/wp-content/uploads/2016/06/IMG_0029-577x1024.jpg 577w, https://iotexpert.com/wp-content/uploads/2016/06/IMG_0029.jpg 640w" sizes="(max-width: 169px) 100vw, 169px" /></a></p>
<p>This App is built up with four files</p>
<ol>
<li>ViewController.swift: an object which controls the screen (button clicks)</li>
<li>BluetoothNeighborhood.swift: an object which controls the Bluetooth in the phone and represents the CY8CKIT021 board (the Model)</li>
<li>globals.swift: Defines the NSNotifications that can be sent</li>
<li>Main.storyboard: The screen layout</li>
</ol>
<p>The code will do the following:</p>
<ol>
<li>When the ViewController (VC) starts it will instantiate a BluetoothNeighborhood (BN) object</li>
<li>VC: Tell the BN to start the bluetooth central in the phone</li>
<li>BN: Scan for BLE Peripherals that are advertising the CY8CKIT-021 Service UUID</li>
<li>BN: When it hears the peripheral with the correct UUID then connect</li>
<li>BN: Read the state of the button0 and led0 then send an NSNotification</li>
<li>BN: Turn on the notify for button0 (to cause the PRoC to send an NSNotification when there are changes)</li>
<li>VC: update the screen when it gets the NSNotification from (5)</li>
<li>VC: If the LED0 switch on the screen is switched then tell the BN to write to the PRoC</li>
<li>BN: If the button0 is changed then send an NSNotification to the VC</li>
<li>VC: If there is an NSNotification (9) of a button0 change then update the screen</li>
<li>VC: If the bootloader button is pressed tell the BN to write the bootloader characteristic</li>
<li>BN: If there is a disconnect event then send an NSNotification to the VC to disable the GUI elements and start scanning again (step 3)</li>
</ol>
<h2>ViewController.swift</h2>
<p>The viewDidLoad method runs when the Apps starts and loads the first screen.  This method</p>
<ol>
<li>Initializes the BluetoothNeighborhood object</li>
<li>Tell it to start the bluetooth scanning</li>
<li>Disables the UI buttons</li>
<li>Then registers with the NSNotificationCenter that it wants to hear the 4 possible messages that the model can send
<ol>
<li>Connect: enable the buttons</li>
<li>Disconnect: disable the buttons</li>
<li>UpdateLED: reflect the current state of the LED on the screen</li>
<li>UpdateButton: reflect the current state of the button on the screen</li>
</ol>
</li>
</ol>
<p>&nbsp;</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="swift"><pre class="de1"><span class="co1">//</span>
<span class="co1">//  ViewController.swift</span>
<span class="co1">//  Example10</span>
<span class="co1">//</span>
<span class="co1">// Project: Example10</span>
<span class="co1">// Kit: CY8CKIT-021 Sheild</span>
<span class="co1">// Baseboard: CY8CKit-44 PSoC4M</span>
<span class="co1">//</span>
<span class="co1">//  This file contains the viewcontroller for the single view application.</span>
<span class="co1">//  Basically when it loads you startup and connect to the bleboard</span>
<span class="co1">//  then display the state of things... or let the user flip the switch</span>
<span class="co1">//</span>
&nbsp;
<span class="kw1">import</span> UIKit
&nbsp;
<span class="kw1">class</span> ViewController<span class="sy0">:</span> <span class="kw13">UIViewController</span> <span class="br0">&#123;</span>
&nbsp;
    <span class="kw1">var</span> bleLand <span class="sy0">:</span> BlueToothNeighborhood<span class="sy0">!</span>
&nbsp;
    <span class="kw1">override</span> <span class="kw1">func</span> viewDidLoad<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">super</span>.<span class="me1">viewDidLoad</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
&nbsp;
        <span class="co1">// bleLand-BlueToothNeighborhood is the model.  It is capable of finding</span>
        <span class="co1">// a CY8CKIT021 and connecting to it. It can also read/write etc</span>
        bleLand = BlueToothNeighborhood<span class="br0">&#40;</span><span class="br0">&#41;</span>
        bleLand.<span class="me1">startUpCentralManager</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
&nbsp;
        <span class="co1">// start with the switch disabled.  it will turn on once there is a connection</span>
        led0switch.<span class="me1">userInteractionEnabled</span> = <span class="kw1">false</span>
        bootLoaderButton.<span class="me1">userInteractionEnabled</span> = <span class="kw1">false</span>
&nbsp;
&nbsp;
        <span class="co1">// The global structure CY8CKITNotifications defines the different notificateions</span>
        <span class="co1">// that can come from the bleLand model.  Basically a connection/disconnection or</span>
        <span class="co1">// and update of the Led0 or Button0 State</span>
&nbsp;
        <span class="co1">// If you get a complete connection then turn on the buttons to start working</span>
        <span class="kw7">NSNotificationCenter</span>.<span class="me1">defaultCenter</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addObserverForName</span><span class="br0">&#40;</span>CY8CKIT021Notifications.<span class="me1">ConnectionComplete</span><span class="sy0">,</span> object<span class="sy0">:</span> <span class="kw1">nil</span><span class="sy0">,</span> queue<span class="sy0">:</span> <span class="kw7">NSOperationQueue</span>.<span class="me1">mainQueue</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> _ <span class="kw1">in</span>
            <span class="kw1">self</span>.<span class="me1">led0switch</span>.<span class="me1">userInteractionEnabled</span> = <span class="kw1">true</span>
            <span class="kw1">self</span>.<span class="me1">bootLoaderButton</span>.<span class="me1">userInteractionEnabled</span> = <span class="kw1">true</span>
        <span class="br0">&#125;</span>
&nbsp;
        <span class="co1">// if you get disconnected then turn off the buttons</span>
        <span class="kw7">NSNotificationCenter</span>.<span class="me1">defaultCenter</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addObserverForName</span><span class="br0">&#40;</span>CY8CKIT021Notifications.<span class="me1">DisconnectedDevice</span><span class="sy0">,</span> object<span class="sy0">:</span> <span class="kw1">nil</span><span class="sy0">,</span> queue<span class="sy0">:</span> <span class="kw7">NSOperationQueue</span>.<span class="me1">mainQueue</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> _ <span class="kw1">in</span>
                <span class="kw1">self</span>.<span class="me1">led0switch</span>.<span class="me1">userInteractionEnabled</span> = <span class="kw1">false</span>
                <span class="kw1">self</span>.<span class="me1">bootLoaderButton</span>.<span class="me1">userInteractionEnabled</span> = <span class="kw1">false</span>
            <span class="br0">&#125;</span>
&nbsp;
        <span class="co1">// The we got feedback from the model about the state of the button0</span>
        <span class="kw7">NSNotificationCenter</span>.<span class="me1">defaultCenter</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addObserverForName</span><span class="br0">&#40;</span>CY8CKIT021Notifications.<span class="me1">UpdatedButton0</span><span class="sy0">,</span> object<span class="sy0">:</span> <span class="kw1">nil</span><span class="sy0">,</span> queue<span class="sy0">:</span> <span class="kw7">NSOperationQueue</span>.<span class="me1">mainQueue</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> _ <span class="kw1">in</span> <span class="kw1">self</span>.<span class="me1">button0</span>.<span class="me1">selected</span> = <span class="kw1">self</span>.<span class="me1">bleLand</span>.<span class="me1">button0State</span> <span class="br0">&#125;</span>
&nbsp;
        <span class="co1">// The we got feedback from the model about the state of the led0</span>
        <span class="kw7">NSNotificationCenter</span>.<span class="me1">defaultCenter</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">addObserverForName</span><span class="br0">&#40;</span>CY8CKIT021Notifications.<span class="me1">UpdateLed0</span><span class="sy0">,</span> object<span class="sy0">:</span> <span class="kw1">nil</span><span class="sy0">,</span> queue<span class="sy0">:</span> <span class="kw7">NSOperationQueue</span>.<span class="me1">mainQueue</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> _ <span class="kw1">in</span> <span class="kw1">self</span>.<span class="me1">updateLed0</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#125;</span>
&nbsp;
    <span class="br0">&#125;</span></pre></div></div></div></div></div></div></div>


<p>The GUI part of the code just acts when the button/switch is pressed to send messages to the model.  These methods are linked to the GUI elements on the main.storyboard</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="swift"><pre class="de1">    <span class="co1">// This function grabs the current button0 state from the model and sets the button</span>
    <span class="co1">// to indicate it is either being pressed or not</span>
    <span class="kw1">func</span> updateButton0<span class="br0">&#40;</span><span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
        <span class="kw1">self</span>.<span class="me1">button0</span>.<span class="me1">selected</span> = <span class="kw1">self</span>.<span class="me1">bleLand</span>.<span class="me1">button0State</span>
    <span class="br0">&#125;</span>
&nbsp;
    <span class="co1">// This functiong rabs the current led0 state from the model and then flips the </span>
    <span class="co1">// switch the right way</span>
    <span class="kw1">func</span> updateLed0<span class="br0">&#40;</span><span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
        led0switch.<span class="me1">on</span> = bleLand.<span class="me1">led0State</span>
    <span class="br0">&#125;</span>
&nbsp;
    <span class="kw2">@IBOutlet</span> <span class="kw1">weak</span> <span class="kw1">var</span> button0<span class="sy0">:</span> <span class="kw13">UIButton</span><span class="sy0">!</span>
    <span class="kw2">@IBOutlet</span> <span class="kw1">weak</span> <span class="kw1">var</span> led0switch<span class="sy0">:</span> <span class="kw13">UISwitch</span><span class="sy0">!</span>
&nbsp;
    <span class="co1">// When the user flips the switch you need to write the updated value to the model</span>
    <span class="kw2">@IBAction</span> <span class="kw1">func</span> led0SwitchAction<span class="br0">&#40;</span>sender<span class="sy0">:</span> <span class="kw13">UISwitch</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp;
            bleLand.<span class="me1">writeLed0Characteristic</span><span class="br0">&#40;</span>sender.<span class="me1">on</span><span class="br0">&#41;</span>
    <span class="br0">&#125;</span>
&nbsp;
    <span class="co1">// If the user presses the bootload button then send the bootload command</span>
    <span class="co1">// this will cause and immediate BLE disconnect... etc</span>
    <span class="kw2">@IBOutlet</span> <span class="kw1">weak</span> <span class="kw1">var</span> bootLoaderButton<span class="sy0">:</span> <span class="kw13">UIButton</span><span class="sy0">!</span>
    <span class="kw2">@IBAction</span> <span class="kw1">func</span> startBootLoader<span class="br0">&#40;</span>sender<span class="sy0">:</span> <span class="kw6">AnyObject</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        bleLand.<span class="me1">startBootloader</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
    <span class="br0">&#125;</span></pre></div></div></div></div></div></div></div>


<h1>BluetoothNeighborhood</h1>
<p>This file contains all of the code that interacts with the CY8CKIT021 board.  The first block of code defines a structure with a list of the UUIDs that we need to search for.  These are defined in the Bluetooth Component Customizer from the PRoC firmware.</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="swift"><pre class="de1"><span class="co1">// BlueToothNeighborhood.swift</span>
<span class="co1">//</span>
<span class="co1">// Project: Example10</span>
<span class="co1">// Kit: CY8CKIT-021 Sheild</span>
<span class="co1">// Baseboard: CY8CKit-44 PSoC4M</span>
<span class="co1">//</span>
<span class="co1">// This file contains the model for the CY8CKIT021 board with 1 LED0 and 1 Button 0</span>
<span class="co1">//</span>
&nbsp;
<span class="kw1">import</span> CoreBluetooth
&nbsp;
&nbsp;
<span class="co1">// This structure conatains the UUIDS for the services and characteristics on the board</span>
<span class="co1">// it MUST match what you defined in the creator BLE Configuration Wizard</span>
<span class="kw1">private</span> <span class="kw1">struct</span> BLEParameters <span class="br0">&#123;</span>
    <span class="kw1">static</span> <span class="kw1">let</span> CY8CKIT021Service = CBUUID<span class="br0">&#40;</span>string<span class="sy0">:</span> <span class="st0">&quot;00000000-0000-1000-8000-00805F9B3400&quot;</span><span class="br0">&#41;</span>
    <span class="kw1">static</span> <span class="kw1">let</span> bootloadCharactersticUUID = CBUUID<span class="br0">&#40;</span>string<span class="sy0">:</span><span class="st0">&quot;00000000-0000-1000-8000-00805F9B3401&quot;</span><span class="br0">&#41;</span>
    <span class="kw1">static</span> <span class="kw1">let</span> ledCharactersticUUID = CBUUID<span class="br0">&#40;</span>string<span class="sy0">:</span><span class="st0">&quot;00000000-0000-1000-8000-00805F9B3402&quot;</span><span class="br0">&#41;</span>
    <span class="kw1">static</span> <span class="kw1">let</span> buttonCharactersticUUID = CBUUID<span class="br0">&#40;</span>string<span class="sy0">:</span><span class="st0">&quot;00000000-0000-1000-8000-00805F9B3404&quot;</span><span class="br0">&#41;</span>
&nbsp;
<span class="br0">&#125;</span></pre></div></div></div></div></div></div></div>


<p>The next block of code</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="swift"><pre class="de1"><span class="co1">// The model for the board</span>
<span class="co1">// The BlueToothNeighborhood has BOTH the board model and the Bluetooth model.  This</span>
<span class="co1">// makes the code slightly simpler to explain but is a bit weird architectururally</span>
<span class="kw1">class</span> BlueToothNeighborhood<span class="sy0">:</span> <span class="kw7">NSObject</span><span class="sy0">,</span> CBCentralManagerDelegate<span class="sy0">,</span> CBPeripheralDelegate  <span class="br0">&#123;</span>
&nbsp;
    <span class="kw1">private</span> <span class="kw1">var</span> centralManager <span class="sy0">:</span> CBCentralManager<span class="sy0">!</span>
    <span class="kw1">private</span> <span class="kw1">var</span> CY8CKIT021Board <span class="sy0">:</span> CBPeripheral?
    <span class="kw1">private</span> <span class="kw1">var</span> CY8CKIT021Service <span class="sy0">:</span> CBService<span class="sy0">!</span>
    <span class="kw1">private</span> <span class="kw1">var</span> led0Characteristic <span class="sy0">:</span> CBCharacteristic<span class="sy0">!</span>
    <span class="kw1">private</span> <span class="kw1">var</span> button0Characteristic <span class="sy0">:</span> CBCharacteristic<span class="sy0">!</span>
    <span class="kw1">private</span> <span class="kw1">var</span> bootloadCharacteristic <span class="sy0">:</span> CBCharacteristic<span class="sy0">!</span>
&nbsp;
    <span class="co1">// This function is called by the main view controller to get things going</span>
    <span class="kw1">func</span> startUpCentralManager<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        centralManager = CBCentralManager<span class="br0">&#40;</span>delegate<span class="sy0">:</span> <span class="kw1">self</span><span class="sy0">,</span> queue<span class="sy0">:</span> <span class="kw1">nil</span><span class="br0">&#41;</span>
    <span class="br0">&#125;</span>
&nbsp;
    <span class="co1">// This is the bluetooth delegate function</span>
    <span class="kw2">@objc</span> <span class="kw1">func</span> centralManagerDidUpdateState<span class="br0">&#40;</span>central<span class="sy0">:</span> CBCentralManager<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">switch</span> <span class="br0">&#40;</span>central.<span class="me1">state</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">case</span> .<span class="me1">PoweredOff</span><span class="sy0">:</span> <span class="kw1">break</span>
        <span class="kw1">case</span> .<span class="me1">PoweredOn</span><span class="sy0">:</span>
            <span class="kw3">print</span><span class="br0">&#40;</span><span class="st0">&quot;Bluetooth is on - Starting scan&quot;</span><span class="br0">&#41;</span>
            <span class="co1">// start scanning for a device that we can talk to</span>
            centralManager.<span class="me1">scanForPeripheralsWithServices</span><span class="br0">&#40;</span><span class="br0">&#91;</span>BLEParameters.<span class="me1">CY8CKIT021Service</span><span class="br0">&#93;</span><span class="sy0">,</span> options<span class="sy0">:</span> <span class="br0">&#91;</span>CBCentralManagerScanOptionAllowDuplicatesKey<span class="sy0">:</span><span class="kw1">false</span><span class="br0">&#93;</span><span class="br0">&#41;</span>
&nbsp;
        <span class="kw1">case</span> .<span class="me1">Resetting</span><span class="sy0">:</span> <span class="kw1">break</span>
        <span class="kw1">case</span> .<span class="me1">Unauthorized</span><span class="sy0">:</span> <span class="kw1">break</span>
        <span class="kw1">case</span> .<span class="me1">Unknown</span><span class="sy0">:</span><span class="kw1">break</span>
        <span class="kw1">case</span> .<span class="me1">Unsupported</span><span class="sy0">:</span><span class="kw1">break</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span>
&nbsp;
    <span class="co1">// This delegate function is called by the bluetooth when it finds a device</span>
    <span class="co1">// that matches our UUID that we told it when we started the scan</span>
    <span class="kw1">func</span> centralManager<span class="br0">&#40;</span>central<span class="sy0">:</span> CBCentralManager<span class="sy0">,</span> didDiscoverPeripheral peripheral<span class="sy0">:</span> CBPeripheral<span class="sy0">,</span> advertisementData<span class="sy0">:</span> <span class="br0">&#91;</span><span class="kw4">String</span> <span class="sy0">:</span> <span class="kw6">AnyObject</span><span class="br0">&#93;</span><span class="sy0">,</span> RSSI<span class="sy0">:</span> <span class="kw7">NSNumber</span><span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
        <span class="co1">// if you already are connected to a device ignore this one</span>
        <span class="kw1">if</span> CY8CKIT021Board <span class="sy0">==</span> <span class="kw1">nil</span> <span class="br0">&#123;</span>
            <span class="kw3">print</span><span class="br0">&#40;</span><span class="st0">&quot;Found a new Periphal advertising CY8CKIT021 Service&quot;</span><span class="br0">&#41;</span>
            CY8CKIT021Board = peripheral
            centralManager.<span class="me1">stopScan</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
            centralManager.<span class="me1">connectPeripheral</span><span class="br0">&#40;</span>CY8CKIT021Board<span class="sy0">!,</span> options<span class="sy0">:</span> <span class="kw1">nil</span><span class="br0">&#41;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span>
&nbsp;
    <span class="co1">// This delegate is called when a device connection is complete</span>
    <span class="kw1">func</span> centralManager<span class="br0">&#40;</span>central<span class="sy0">:</span> CBCentralManager<span class="sy0">,</span> didConnectPeripheral peripheral<span class="sy0">:</span> CBPeripheral<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw3">print</span><span class="br0">&#40;</span><span class="st0">&quot;Connection complete <span class="es0">\(</span>CY8CKIT021Board) <span class="es0">\(</span>peripheral)&quot;</span><span class="br0">&#41;</span>
        CY8CKIT021Board<span class="sy0">!</span>.<span class="me1">delegate</span> = <span class="kw1">self</span>
        CY8CKIT021Board<span class="sy0">!</span>.<span class="me1">discoverServices</span><span class="br0">&#40;</span><span class="kw1">nil</span><span class="br0">&#41;</span>
    <span class="br0">&#125;</span>
&nbsp;
    <span class="co1">// This delegate is called after the service discovery is complete</span>
    <span class="kw1">func</span> peripheral<span class="br0">&#40;</span>peripheral<span class="sy0">:</span> CBPeripheral<span class="sy0">,</span> didDiscoverServices error<span class="sy0">:</span> <span class="kw7">NSError</span>?<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw3">print</span><span class="br0">&#40;</span><span class="st0">&quot;discovered services&quot;</span><span class="br0">&#41;</span>
        <span class="kw1">for</span> service <span class="kw1">in</span> peripheral.<span class="me1">services</span><span class="sy0">!</span> <span class="br0">&#123;</span>
            <span class="kw3">print</span><span class="br0">&#40;</span><span class="st0">&quot;Found service <span class="es0">\(</span>service)&quot;</span><span class="br0">&#41;</span>
            <span class="kw1">if</span> service.<span class="me1">UUID</span> <span class="sy0">==</span> BLEParameters.<span class="me1">CY8CKIT021Service</span> <span class="br0">&#123;</span>
                CY8CKIT021Service = service <span class="co1">// as! CBService</span>
            <span class="br0">&#125;</span>
        <span class="br0">&#125;</span>
        CY8CKIT021Board<span class="sy0">!</span>.<span class="me1">discoverCharacteristics</span><span class="br0">&#40;</span><span class="kw1">nil</span><span class="sy0">,</span> forService<span class="sy0">:</span> CY8CKIT021Service<span class="br0">&#41;</span>
    <span class="br0">&#125;</span>
&nbsp;
&nbsp;
    <span class="co1">// This delegate is called when the characteristic discovery is complete</span>
    <span class="kw1">func</span> peripheral<span class="br0">&#40;</span>peripheral<span class="sy0">:</span> CBPeripheral<span class="sy0">,</span> didDiscoverCharacteristicsForService service<span class="sy0">:</span> CBService<span class="sy0">,</span> error<span class="sy0">:</span> <span class="kw7">NSError</span>?<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">for</span> characteristic <span class="kw1">in</span> service.<span class="me1">characteristics</span><span class="sy0">!</span>
        <span class="br0">&#123;</span>
&nbsp;
            <span class="kw3">print</span><span class="br0">&#40;</span><span class="st0">&quot;Found characteristic <span class="es0">\(</span>characteristic)&quot;</span><span class="br0">&#41;</span>
            <span class="kw1">switch</span> characteristic.<span class="me1">UUID</span> <span class="br0">&#123;</span>
            <span class="kw1">case</span> BLEParameters.<span class="me1">buttonCharactersticUUID</span><span class="sy0">:</span> button0Characteristic = characteristic
            <span class="kw1">case</span> BLEParameters.<span class="me1">ledCharactersticUUID</span><span class="sy0">:</span> led0Characteristic = characteristic
            <span class="kw1">case</span> BLEParameters.<span class="me1">bootloadCharactersticUUID</span><span class="sy0">:</span> bootloadCharacteristic = characteristic
            <span class="kw1">default</span><span class="sy0">:</span> <span class="kw1">break</span>
            <span class="br0">&#125;</span>
        <span class="br0">&#125;</span>
&nbsp;
        <span class="co1">// You have a complete connection... so find out the current state of the LED0</span>
        <span class="co1">// and Button.. then notify the viewcontroller that things are rolling</span>
&nbsp;
        <span class="co1">// read the led0 characteristic to find out its current state</span>
        CY8CKIT021Board?.<span class="me1">readValueForCharacteristic</span><span class="br0">&#40;</span>led0Characteristic<span class="br0">&#41;</span>
&nbsp;
        <span class="co1">// read the button0 characteristic to find out its current state</span>
        CY8CKIT021Board?.<span class="me1">readValueForCharacteristic</span><span class="br0">&#40;</span>button0Characteristic<span class="br0">&#41;</span>
&nbsp;
        CY8CKIT021Board<span class="sy0">!</span>.<span class="me1">setNotifyValue</span><span class="br0">&#40;</span><span class="kw1">true</span><span class="sy0">,</span> forCharacteristic<span class="sy0">:</span> button0Characteristic<span class="br0">&#41;</span>
        <span class="kw7">NSNotificationCenter</span>.<span class="me1">defaultCenter</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">postNotificationName</span><span class="br0">&#40;</span>CY8CKIT021Notifications.<span class="me1">ConnectionComplete</span><span class="sy0">,</span> object<span class="sy0">:</span> <span class="kw1">nil</span><span class="br0">&#41;</span>
    <span class="br0">&#125;</span>
&nbsp;
    <span class="co1">// disconnected device - start scanning again</span>
    <span class="kw1">func</span> centralManager<span class="br0">&#40;</span>central<span class="sy0">:</span> CBCentralManager<span class="sy0">,</span> didDisconnectPeripheral peripheral<span class="sy0">:</span> CBPeripheral<span class="sy0">,</span> error<span class="sy0">:</span> <span class="kw7">NSError</span>?<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw3">print</span><span class="br0">&#40;</span><span class="st0">&quot;Disconnected <span class="es0">\(</span>peripheral)&quot;</span><span class="br0">&#41;</span>
        CY8CKIT021Board = <span class="kw1">nil</span>
        <span class="kw7">NSNotificationCenter</span>.<span class="me1">defaultCenter</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">postNotificationName</span><span class="br0">&#40;</span>CY8CKIT021Notifications.<span class="me1">DisconnectedDevice</span><span class="sy0">,</span> object<span class="sy0">:</span> <span class="kw1">nil</span><span class="br0">&#41;</span>
        centralManager.<span class="me1">scanForPeripheralsWithServices</span><span class="br0">&#40;</span><span class="br0">&#91;</span>BLEParameters.<span class="me1">CY8CKIT021Service</span><span class="br0">&#93;</span><span class="sy0">,</span> options<span class="sy0">:</span> <span class="br0">&#91;</span>CBCentralManagerScanOptionAllowDuplicatesKey<span class="sy0">:</span><span class="kw1">false</span><span class="br0">&#93;</span><span class="br0">&#41;</span>
&nbsp;
    <span class="br0">&#125;</span></pre></div></div></div></div></div></div></div>


<p>The last block of code is responsible for interacting with the board</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="swift"><pre class="de1"><span class="co1">// start the bootloader...this will cause an immediate disconnect by the board</span>
    <span class="kw1">func</span> startBootloader<span class="br0">&#40;</span><span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
        <span class="kw1">var</span> val<span class="sy0">:</span> <span class="kw4">UInt8</span> = <span class="nu0">1</span> <span class="co1">// it doesnt matter the value... any write will cause the bootloader to start</span>
        <span class="kw1">let</span> ns = <span class="kw7">NSData</span><span class="br0">&#40;</span>bytes<span class="sy0">:</span> <span class="sy0">&amp;</span>amp<span class="sy0">;</span>val<span class="sy0">,</span> length<span class="sy0">:</span> <span class="kw3">sizeof</span><span class="br0">&#40;</span><span class="kw4">UInt8</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
        CY8CKIT021Board<span class="sy0">!</span>.<span class="me1">writeValue</span><span class="br0">&#40;</span>ns<span class="sy0">,</span> forCharacteristic<span class="sy0">:</span> bootloadCharacteristic<span class="sy0">,</span> type<span class="sy0">:</span> CBCharacteristicWriteType.<span class="me1">WithResponse</span><span class="br0">&#41;</span>
    <span class="br0">&#125;</span>
&nbsp;
&nbsp;
    <span class="co1">// a helper function to write the the device</span>
    <span class="kw1">func</span> writeLed0Characteristic<span class="br0">&#40;</span>state<span class="sy0">:</span> <span class="kw4">Bool</span><span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
        <span class="kw1">var</span> val <span class="sy0">:</span> <span class="kw4">Int8</span>
        <span class="kw1">if</span><span class="br0">&#40;</span>state<span class="br0">&#41;</span>
        <span class="br0">&#123;</span>
            val = <span class="nu0">1</span>
        <span class="br0">&#125;</span>
        <span class="kw1">else</span>
        <span class="br0">&#123;</span>
            val = <span class="nu0">0</span>
        <span class="br0">&#125;</span>
        <span class="kw1">let</span> ns = <span class="kw7">NSData</span><span class="br0">&#40;</span>bytes<span class="sy0">:</span> <span class="sy0">&amp;</span>amp<span class="sy0">;</span>val<span class="sy0">,</span> length<span class="sy0">:</span> <span class="kw3">sizeof</span><span class="br0">&#40;</span><span class="kw4">Int8</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
        CY8CKIT021Board<span class="sy0">!</span>.<span class="me1">writeValue</span><span class="br0">&#40;</span>ns<span class="sy0">,</span> forCharacteristic<span class="sy0">:</span> led0Characteristic<span class="sy0">,</span> type<span class="sy0">:</span> CBCharacteristicWriteType.<span class="me1">WithResponse</span><span class="br0">&#41;</span>
    <span class="br0">&#125;</span>
&nbsp;
    <span class="co1">// this is the model of the board</span>
    <span class="kw1">var</span> button0State <span class="sy0">:</span> <span class="kw4">Bool</span> = <span class="kw1">false</span> 
    <span class="kw1">var</span> led0State <span class="sy0">:</span> <span class="kw4">Bool</span> = <span class="kw1">false</span> <span class="co1">// assume that it is off</span>
&nbsp;
    <span class="co1">// This delegate function is called when an updated value is received from the Bluetooth Stack</span>
    <span class="kw1">func</span> peripheral<span class="br0">&#40;</span>peripheral<span class="sy0">:</span> CBPeripheral<span class="sy0">,</span> didUpdateValueForCharacteristic characteristic<span class="sy0">:</span> CBCharacteristic<span class="sy0">,</span> error<span class="sy0">:</span> <span class="kw7">NSError</span>?<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="kw1">if</span> characteristic <span class="sy0">==</span> button0Characteristic <span class="br0">&#123;</span>
            <span class="kw1">var</span> out<span class="sy0">:</span> <span class="kw4">UInt8</span> = <span class="nu0">0</span>
            characteristic.<span class="me1">value</span><span class="sy0">!</span>.<span class="me1">getBytes</span><span class="br0">&#40;</span><span class="sy0">&amp;</span>amp<span class="sy0">;</span>out<span class="sy0">,</span> length<span class="sy0">:</span><span class="kw3">sizeof</span><span class="br0">&#40;</span><span class="kw4">UInt8</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
            <span class="kw1">if</span><span class="br0">&#40;</span>out <span class="sy0">==</span> <span class="nu0">0</span><span class="br0">&#41;</span>
            <span class="br0">&#123;</span>
                button0State = <span class="kw1">false</span>
            <span class="br0">&#125;</span>
            <span class="kw1">else</span>
            <span class="br0">&#123;</span>
                button0State = <span class="kw1">true</span>
            <span class="br0">&#125;</span>
            <span class="kw7">NSNotificationCenter</span>.<span class="me1">defaultCenter</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">postNotificationName</span><span class="br0">&#40;</span>CY8CKIT021Notifications.<span class="me1">UpdatedButton0</span><span class="sy0">,</span> object<span class="sy0">:</span> <span class="kw1">nil</span><span class="br0">&#41;</span>
        <span class="br0">&#125;</span>
&nbsp;
        <span class="kw1">if</span> characteristic <span class="sy0">==</span> led0Characteristic <span class="br0">&#123;</span>
            <span class="kw1">var</span> out<span class="sy0">:</span> NSInteger = <span class="nu0">0</span>
            characteristic.<span class="me1">value</span><span class="sy0">!</span>.<span class="me1">getBytes</span><span class="br0">&#40;</span><span class="sy0">&amp;</span>amp<span class="sy0">;</span>out<span class="sy0">,</span> length<span class="sy0">:</span><span class="kw3">sizeof</span><span class="br0">&#40;</span><span class="kw4">UInt8</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
            <span class="kw1">if</span><span class="br0">&#40;</span>out <span class="sy0">==</span> <span class="nu0">0</span><span class="br0">&#41;</span>
            <span class="br0">&#123;</span>
                led0State = <span class="kw1">false</span>
            <span class="br0">&#125;</span>
            <span class="kw1">else</span>
            <span class="br0">&#123;</span>
                led0State = <span class="kw1">true</span>
            <span class="br0">&#125;</span>
            <span class="kw7">NSNotificationCenter</span>.<span class="me1">defaultCenter</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">postNotificationName</span><span class="br0">&#40;</span>CY8CKIT021Notifications.<span class="me1">UpdateLed0</span><span class="sy0">,</span> object<span class="sy0">:</span> <span class="kw1">nil</span><span class="br0">&#41;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span></pre></div></div></div></div></div></div></div>


<p>In the next post Ill show you how to build the Android App.</p>
<p><span><p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >index</th>
<th >description</th>
</tr>
</thead>
<tbody>
<tr><td ><a href="https://iotexpert.com/2016/05/23/cy8ckit-021-a-simple-fmpsoc-ble-demonstration-board/">CY8CKIT-021: A Simple FM/PSoC + BLE Demonstration Board</a></td>
<td >Introduction to CY8CKIT021</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/05/24/cy8ckit-021-the-first-4-example-projects/">CY8CKIT-021: The first four example projects</a></td>
<td >Use the LEDs</td>
<td > Buzzer</td>
<td > 7-Segment display and the Potentiometer</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/05/25/cy8ckit-021-the-next-3-example-projects/">CY8CKIT-021: The next three example projects</a></td>
<td >Use theThermistor and two Capsense Examples</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/06/06/cy8ckit-021-the-proc-ble-firmware/">CY8CKIT-021: Bootloading the PRoC</a></td>
<td >How to put firmware into the PRoC</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/05/31/cy8ckit-021-the-bleiot-component/">CY8CKIT-021: The BLEIOT Component</a></td>
<td >A custom component to communicate with the PRoC/PSoC</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/06/02/cy8ckit-021-using-the-bleiot-component/">CY8CKIT-021: Using the BLEIOT Component</a></td>
<td >A full example of the tho MCUs talking</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/06/06/cy8ckit-021-the-proc-ble-firmware/">CY8CKIT-021: The PRoC BLE Firmware</a></td>
<td >How to make PRoC Firmware and use it with the BLEIOT Component</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/06/13/cy8ckit-021-example-10-the-ios-app/">CY8CKIT-021: Example 10 - the new IOS App</a></td>
<td >How to build and IOS App to talk to the development kit</td>
</tr>
</tbody></table></div></p></span></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/cy8ckit-021-example-10-the-ios-app/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>CY8CKIT-021: The PRoC BLE Firmware</title>
		<link>https://iotexpert.com/cy8ckit-021-the-proc-ble-firmware/</link>
					<comments>https://iotexpert.com/cy8ckit-021-the-proc-ble-firmware/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Mon, 06 Jun 2016 09:32:49 +0000</pubDate>
				<category><![CDATA[Cy8CKIT-021]]></category>
		<category><![CDATA[DevKits]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=1587</guid>

					<description><![CDATA[In the next few posts I am going to show how to build a very simple BLE project for the shield, debug it using CySmart, make an iOS app, and finally make an Android app.  I am going to try to only put in the bare minimum of feature that will enable you to see [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In the next few posts I am going to show how to build a very simple BLE project for the shield, debug it using CySmart, make an iOS app, and finally make an Android app.  I am going to try to only put in the bare minimum of feature that will enable you to see the whole project work from end to end.  This next series of posts will use</p>
<ul>
<li>LED0: which can be turned on/off from the from the Android and iOS App</li>
<li>Button0: which will be displayed as on/off on the Android and iOS App</li>
<li>Bootload: you will be able to trigger the bootloader from the baseboard or by writing into the BLE Bootload characteristic</li>
<li>The blue LED attached to the PRoC will blink when advertising and be solid when connected</li>
</ul>
<p>All of this firmware is available as Example10a (for the PRoC) and Example10b for the PSoC4200m in the firmware directory on <a href="http://github.com/iotexpert/CY8CKIT-021" target="_blank">github.com/iotexpert/CY8CKIT-021</a></p>
<h2>Example 10a: The PRoC Firmware</h2>
<p>The schematic for this project has two pages.  The first page has everything except for the bootloadble.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-30-at-10.11.35-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-30-at-10.11.35-AM.png" alt="Screen Shot 2016-05-30 at 10.11.35 AM" width="630" height="518" class="alignnone size-large wp-image-1592" srcset="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-30-at-10.11.35-AM.png 630w, https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-30-at-10.11.35-AM-600x493.png 600w, https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-30-at-10.11.35-AM-300x247.png 300w" sizes="(max-width: 630px) 100vw, 630px" /></a></p>
<p>The second page of the schematic has the bootloadable.  This allows me to &#8220;disable&#8221; that page if I am not using the Bootloader</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-30-at-10.14.59-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-30-at-10.14.59-AM.png" alt="Screen Shot 2016-05-30 at 10.14.59 AM" width="407" height="450" class="alignnone size-full wp-image-1593" srcset="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-30-at-10.14.59-AM.png 407w, https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-30-at-10.14.59-AM-271x300.png 271w" sizes="(max-width: 407px) 100vw, 407px" /></a></p>
<p>The BLE component has the &#8220;CY8CKIT021&#8221; service with three characteristics one for LED0, Button and Bootload,  The Button has a notify CCCD setup.  All three are uint8s.</p>
<p><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-30-at-10.11.56-AM.png" alt="Screen Shot 2016-05-30 at 10.11.56 AM" width="918" height="846" class="alignnone size-full wp-image-1591" srcset="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-30-at-10.11.56-AM.png 918w, https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-30-at-10.11.56-AM-600x553.png 600w, https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-30-at-10.11.56-AM-300x276.png 300w, https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-30-at-10.11.56-AM-768x708.png 768w" sizes="(max-width: 918px) 100vw, 918px" /></p>
<p>This program is broken up into three functions</p>
<ul>
<li><strong>updateGattDB</strong>: A helper function that can take data as a void* and write it into the correct place in the GattDB.  For example when the app changes the LED0 Characteristic you need to write that update into the GattDB.  This function is generic which will support the same logic on a bunch of different characteristic (for instance when I put in all of the other characteristics LED0/1, Button0/1, Pot, &#8230;)</li>
<li><strong>BleCallBack: </strong>This function  processes the BLE Events
<ul>
<li>Stack on or disconnect: start advertising and start blinking</li>
<li>Write of characterstic from Central: store the written value into the GattDB and do something</li>
<li>Connect: update the GattDB and turn on the LED</li>
</ul>
</li>
<li><strong>main:</strong> This function is very simple and forms the main loop of the program.
<ul>
<li>Start the components</li>
<li>If there is a remote from the 4200M side then update the GattDB</li>
</ul>
</li>
</ul>
<p>First, the updateGattDB helper function.</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="c"><pre class="de1"><span class="co1">// updateGattDB() -  </span>
<span class="co1">//</span>
<span class="co1">// Arguments: </span>
<span class="co1">//  uint8* val  - a pointer to the bytes that need to be writted into the GATTDB</span>
<span class="co1">//  int size - the number of bytes that need to be written into the GATTDB</span>
<span class="co1">//  uint8 notify - if the NOTIFY is on then send a notification</span>
<span class="co1">//  CYBLE_GATT_DB_ATTR_HANDLE_T handle - a handle to the entry in the gatt table</span>
<span class="co1">//  uint8 flags - a request </span>
<span class="co1">//   </span>
<span class="co1">// This is a helper function that will update the GATT database with a value.  It update the field of</span>
<span class="co1">// the &quot;CYBLE_GATT_DB_ATTR_HANDLE_T&quot;</span>
&nbsp;
<span class="kw4">void</span> updateGattDB<span class="br0">&#40;</span><span class="kw4">uint8</span> <span class="sy0">*</span>val<span class="sy0">,</span><span class="kw4">int</span> size<span class="sy0">,</span><span class="kw4">uint8</span> notify<span class="sy0">,</span> CYBLE_GATT_DB_ATTR_HANDLE_T handle<span class="sy0">,</span><span class="kw4">uint8</span> flags<span class="br0">&#41;</span>
<span class="br0">&#123;</span>
&nbsp;
    <span class="co1">// this little block of code doesnt make me happy... </span>
    <span class="kw1">switch</span><span class="br0">&#40;</span>CyBle_GetState<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
        <span class="kw1">case</span> CYBLE_STATE_ADVERTISING<span class="sy0">:</span>
            <span class="kw1">return</span><span class="sy0">;</span>
        <span class="kw1">case</span> CYBLE_STATE_DISCONNECTED<span class="sy0">:</span>
            <span class="kw1">return</span><span class="sy0">;</span>
        <span class="kw1">case</span> CYBLE_STATE_STOPPED<span class="sy0">:</span>
            <span class="kw1">return</span><span class="sy0">;</span>
        <span class="kw1">case</span> CYBLE_STATE_CONNECTED<span class="sy0">:</span>
            <span class="kw2">break</span><span class="sy0">;</span>
        <span class="kw1">case</span> CYBLE_STATE_INITIALIZING<span class="sy0">:</span>
            <span class="kw1">return</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
    <span class="co1">//update the GATT Database</span>
    CYBLE_GATTS_HANDLE_VALUE_NTF_T 	tempHandle<span class="sy0">;</span>
    tempHandle.<span class="me1">attrHandle</span> <span class="sy0">=</span> handle<span class="sy0">;</span>
  	tempHandle.<span class="me1">value</span>.<span class="me1">val</span> <span class="sy0">=</span> val<span class="sy0">;</span>
    tempHandle.<span class="me1">value</span>.<span class="me1">len</span> <span class="sy0">=</span> size<span class="sy0">;</span>
    CYBLE_GATT_ERR_CODE_T ret <span class="sy0">=</span> CyBle_GattsWriteAttributeValue<span class="br0">&#40;</span><span class="sy0">&amp;</span>amp<span class="sy0">;</span>tempHandle<span class="sy0">,</span><span class="nu0">0</span><span class="sy0">,&amp;</span>amp<span class="sy0">;</span>cyBle_connHandle<span class="sy0">,</span>flags<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">if</span><span class="br0">&#40;</span>ret <span class="sy0">!=</span> CYBLE_GATT_ERR_NONE<span class="br0">&#41;</span> <span class="co1">// this is really not a good place to be.</span>
    <span class="br0">&#123;</span>
        <span class="kw1">return</span><span class="sy0">;</span>
&nbsp;
        CYASSERT<span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="kw1">while</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
    <span class="co1">// if peer initiated then write response.</span>
    <span class="kw1">if</span><span class="br0">&#40;</span>flags <span class="sy0">==</span> CYBLE_GATT_DB_PEER_INITIATED<span class="br0">&#41;</span>
        CyBle_GattsWriteRsp<span class="br0">&#40;</span>cyBle_connHandle<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">else</span> <span class="kw1">if</span><span class="br0">&#40;</span>notify<span class="br0">&#41;</span> <span class="co1">// If notify &amp;amp; local initiated </span>
    <span class="br0">&#123;</span>
        CyBle_GattsNotification<span class="br0">&#40;</span>cyBle_connHandle<span class="sy0">,&amp;</span>amp<span class="sy0">;</span>tempHandle<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>    
<span class="br0">&#125;</span></pre></div></div></div></div></div></div></div>


<p>The next block of code is the BleCallback.  One cool thing that PSoC Creator does is give you the ability to #ifndef to remove code when a schematic page is disabled.  In the code below when I have &#8220;disabled&#8221; the Bootloadable schematic page it will remove that block of code from my firmware.</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="c"><pre class="de1"><span class="coMULTI">/***************************************************************
 * Function to handle the BLE stack
 **************************************************************/</span>
<span class="kw4">void</span> BleCallBack<span class="br0">&#40;</span><span class="kw4">uint32</span> event<span class="sy0">,</span> <span class="kw4">void</span><span class="sy0">*</span> eventParam<span class="br0">&#41;</span>
<span class="br0">&#123;</span>
    CYBLE_GATTS_WRITE_REQ_PARAM_T <span class="sy0">*</span>wrReqParam<span class="sy0">;</span>
    <span class="kw1">switch</span><span class="br0">&#40;</span>event<span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
        <span class="coMULTI">/* if there is a disconnect or the stack just turned on from a reset then start the advertising and turn on the LED blinking */</span>
        <span class="kw1">case</span> CYBLE_EVT_STACK_ON<span class="sy0">:</span>
        <span class="kw1">case</span> CYBLE_EVT_GAP_DEVICE_DISCONNECTED<span class="sy0">:</span>
            CyBle_GappStartAdvertisement<span class="br0">&#40;</span>CYBLE_ADVERTISING_FAST<span class="br0">&#41;</span><span class="sy0">;</span>
            PWM_Start<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="kw3">memset</span><span class="br0">&#40;</span><span class="sy0">&amp;</span>amp<span class="sy0">;</span>notifyFlags<span class="sy0">,</span><span class="nu0">0</span><span class="sy0">,</span><span class="kw4">sizeof</span><span class="br0">&#40;</span>notifyFlags<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="kw2">break</span><span class="sy0">;</span>       
&nbsp;
        <span class="kw1">case</span> CYBLE_EVT_GAP_DEVICE_CONNECTED<span class="sy0">:</span>           
            PWM_Stop<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            updateGattDB<span class="br0">&#40;</span><span class="sy0">&amp;</span>amp<span class="sy0">;</span>BLEIOT_local.<span class="me1">led0</span><span class="sy0">,</span><span class="kw4">sizeof</span><span class="br0">&#40;</span>BLEIOT_local.<span class="me1">led0</span><span class="br0">&#41;</span><span class="sy0">,</span>notifyFlags.<span class="me1">led0</span><span class="sy0">,</span>CYBLE_CY8CKIT021_LED0_CHAR_HANDLE<span class="sy0">,</span>CYBLE_GATT_DB_LOCALLY_INITIATED<span class="br0">&#41;</span><span class="sy0">;</span>
            updateGattDB<span class="br0">&#40;</span><span class="sy0">&amp;</span>amp<span class="sy0">;</span>BLEIOT_local.<span class="me1">button0</span><span class="sy0">,</span><span class="kw4">sizeof</span><span class="br0">&#40;</span>BLEIOT_local.<span class="me1">button0</span><span class="br0">&#41;</span><span class="sy0">,</span>notifyFlags.<span class="me1">button0</span><span class="sy0">,</span>CYBLE_CY8CKIT021_BUTTON0_CHAR_HANDLE<span class="sy0">,</span>CYBLE_GATT_DB_LOCALLY_INITIATED<span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="kw2">break</span><span class="sy0">;</span>
&nbsp;
        <span class="kw1">case</span> CYBLE_EVT_GATTS_WRITE_REQ<span class="sy0">:</span>
            wrReqParam <span class="sy0">=</span> <span class="br0">&#40;</span>CYBLE_GATTS_WRITE_REQ_PARAM_T <span class="sy0">*</span><span class="br0">&#41;</span> eventParam<span class="sy0">;</span>
           <span class="co1">// Bootload</span>
            <span class="co2">#ifndef BootLoadable__DISABLED</span>
            <span class="kw1">if</span><span class="br0">&#40;</span>wrReqParam<span class="sy0">-&amp;</span>gt<span class="sy0">;</span>handleValPair.<span class="me1">attrHandle</span> <span class="sy0">==</span> CYBLE_CY8CKIT021_BOOTLOAD_CHAR_HANDLE<span class="br0">&#41;</span>
            <span class="br0">&#123;</span>
                <span class="kw1">if</span><span class="br0">&#40;</span>wrReqParam<span class="sy0">-&amp;</span>gt<span class="sy0">;</span>handleValPair.<span class="me1">value</span>.<span class="me1">val</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span> Bootloadable_Load<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
            <span class="br0">&#125;</span>
            <span class="co2">#endif</span>
&nbsp;
            <span class="co1">// LED0</span>
            <span class="kw1">if</span><span class="br0">&#40;</span>wrReqParam<span class="sy0">-&amp;</span>gt<span class="sy0">;</span>handleValPair.<span class="me1">attrHandle</span> <span class="sy0">==</span> CYBLE_CY8CKIT021_LED0_CHAR_HANDLE<span class="br0">&#41;</span>
            <span class="br0">&#123;</span>
                BLEIOT_updateLed0<span class="br0">&#40;</span>wrReqParam<span class="sy0">-&amp;</span>gt<span class="sy0">;</span>handleValPair.<span class="me1">value</span>.<span class="me1">val</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
                updateGattDB<span class="br0">&#40;</span>wrReqParam<span class="sy0">-&amp;</span>gt<span class="sy0">;</span>handleValPair.<span class="me1">value</span>.<span class="me1">val</span><span class="sy0">,</span><span class="nu0">1</span><span class="sy0">,</span>notifyFlags.<span class="me1">led0</span><span class="sy0">,</span>CYBLE_CY8CKIT021_LED0_CHAR_HANDLE<span class="sy0">,</span>CYBLE_GATT_DB_PEER_INITIATED<span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="br0">&#125;</span>
&nbsp;
            <span class="kw1">if</span><span class="br0">&#40;</span>wrReqParam<span class="sy0">-&amp;</span>gt<span class="sy0">;</span>handleValPair.<span class="me1">attrHandle</span> <span class="sy0">==</span> CYBLE_CY8CKIT021_LED0_CCCD_DESC_HANDLE<span class="br0">&#41;</span>
            <span class="br0">&#123;</span>
                notifyFlags.<span class="me1">led0</span> <span class="sy0">=</span> wrReqParam<span class="sy0">-&amp;</span>gt<span class="sy0">;</span>handleValPair.<span class="me1">value</span>.<span class="me1">val</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="sy0">;</span>
                CyBle_GattsWriteRsp<span class="br0">&#40;</span>cyBle_connHandle<span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="br0">&#125;</span>
&nbsp;
            <span class="co1">// BUTTON 0</span>
            <span class="kw1">if</span><span class="br0">&#40;</span>wrReqParam<span class="sy0">-&amp;</span>gt<span class="sy0">;</span>handleValPair.<span class="me1">attrHandle</span> <span class="sy0">==</span> CYBLE_CY8CKIT021_BUTTON0_CCCD_DESC_HANDLE<span class="br0">&#41;</span>
            <span class="br0">&#123;</span>
                notifyFlags.<span class="me1">button0</span> <span class="sy0">=</span> wrReqParam<span class="sy0">-&amp;</span>gt<span class="sy0">;</span>handleValPair.<span class="me1">value</span>.<span class="me1">val</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="sy0">;</span>
                CyBle_GattsWriteRsp<span class="br0">&#40;</span>cyBle_connHandle<span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="br0">&#125;</span>
        <span class="kw2">break</span><span class="sy0">;</span>  
&nbsp;
        <span class="kw1">default</span><span class="sy0">:</span>
        <span class="kw2">break</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div></div></div></div></div></div>


<p>Finally the last block of code is the main loop</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="c"><pre class="de1"><span class="kw4">int</span> main<span class="br0">&#40;</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
    CyGlobalIntEnable<span class="sy0">;</span>
    BLEIOT_Start<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    EZI2C_Start<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    EZI2C_EzI2CSetBuffer1<span class="br0">&#40;</span><span class="kw4">sizeof</span><span class="br0">&#40;</span>BLEIOT_local<span class="br0">&#41;</span><span class="sy0">,</span><span class="nu0">1</span><span class="sy0">,</span><span class="br0">&#40;</span><span class="kw4">uint8</span> <span class="sy0">*</span><span class="br0">&#41;</span><span class="sy0">&amp;</span>amp<span class="sy0">;</span>BLEIOT_local<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    CyBle_Start<span class="br0">&#40;</span>BleCallBack<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    <span class="kw1">for</span><span class="br0">&#40;</span><span class="sy0">;;</span><span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
&nbsp;
        <span class="co2">#ifndef BootLoadable__DISABLED</span>
        <span class="co1">// if they write into the BLEIOT_local.bootload (from EzI2C)</span>
        <span class="kw1">if</span><span class="br0">&#40;</span>BLEIOT_getDirtyFlags<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">&amp;</span>amp<span class="sy0">;</span> BLEIOT_FLAG_BOOTLOAD <span class="sy0">||</span> BLEIOT_local.<span class="me1">bootload</span><span class="br0">&#41;</span>
        <span class="br0">&#123;</span>
            <span class="co1">// enter the bootloader</span>
            Bootloadable_Load<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
&nbsp;
        <span class="co2">#endif</span>
&nbsp;
        <span class="kw1">if</span><span class="br0">&#40;</span>BLEIOT_getDirtyFlags<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">&amp;</span>amp<span class="sy0">;</span> BLEIOT_FLAG_LED0<span class="br0">&#41;</span>
        <span class="br0">&#123;</span>
            BLEIOT_updateLed0<span class="br0">&#40;</span>BLEIOT_remote.<span class="me1">led0</span><span class="br0">&#41;</span><span class="sy0">;</span>
            updateGattDB<span class="br0">&#40;</span><span class="sy0">&amp;</span>amp<span class="sy0">;</span>BLEIOT_local.<span class="me1">led0</span><span class="sy0">,</span><span class="kw4">sizeof</span><span class="br0">&#40;</span>BLEIOT_local.<span class="me1">led0</span><span class="br0">&#41;</span><span class="sy0">,</span>notifyFlags.<span class="me1">led0</span><span class="sy0">,</span>CYBLE_CY8CKIT021_LED0_CHAR_HANDLE<span class="sy0">,</span>CYBLE_GATT_DB_LOCALLY_INITIATED<span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
&nbsp;
        <span class="kw1">if</span><span class="br0">&#40;</span>BLEIOT_getDirtyFlags<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">&amp;</span>amp<span class="sy0">;</span> BLEIOT_FLAG_BUTTON0<span class="br0">&#41;</span>
        <span class="br0">&#123;</span>
            BLEIOT_updateButton0<span class="br0">&#40;</span>BLEIOT_remote.<span class="me1">button0</span><span class="br0">&#41;</span><span class="sy0">;</span>
            updateGattDB<span class="br0">&#40;</span><span class="sy0">&amp;</span>amp<span class="sy0">;</span>BLEIOT_local.<span class="me1">button0</span><span class="sy0">,</span><span class="kw4">sizeof</span><span class="br0">&#40;</span>BLEIOT_local.<span class="me1">button0</span><span class="br0">&#41;</span><span class="sy0">,</span>notifyFlags.<span class="me1">button0</span><span class="sy0">,</span>CYBLE_CY8CKIT021_BUTTON0_CHAR_HANDLE<span class="sy0">,</span>CYBLE_GATT_DB_LOCALLY_INITIATED<span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
&nbsp;
        CyBle_ProcessEvents<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        CyBle_EnterLPM<span class="br0">&#40;</span>CYBLE_BLESS_DEEPSLEEP<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div></div></div></div></div></div>


<h2>PSoC FIRMWARE</h2>
<p>To make this project work I built the simplest firmware that I can think of for the PSoC4200M.  The schematic has only the BLEIOT, CapSense and the LED.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-30-at-11.11.51-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-30-at-11.11.51-AM.png" alt="Screen Shot 2016-05-30 at 11.11.51 AM" width="443" height="289" class="alignnone size-full wp-image-1596" srcset="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-30-at-11.11.51-AM.png 443w, https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-30-at-11.11.51-AM-300x196.png 300w" sizes="(max-width: 443px) 100vw, 443px" /></a></p>
<p>The firmware just</p>
<ul>
<li>Starts the components</li>
<li>If the capsense is not busy then it updates the Button0 state if it has changed then rescans</li>
<li>If the PRoC side writes the LED0 then it updates the state.</li>
</ul>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="c"><pre class="de1"><span class="co1">// Project: Example10b - PSoC</span>
<span class="co1">// Kit: CY8CKIT-021 Sheild</span>
<span class="co1">// Baseboard: CY8CKit-44 PSoC4M</span>
<span class="co1">//</span>
<span class="co1">// This project demonstrates the simplest connection to the PRoC and BLE</span>
<span class="co1">// It updates the LED0 based on writes from the PRoC side</span>
<span class="co1">// It sends out updates to the PRoC based on button processes</span>
<span class="co2">#include &lt;project.h&gt;</span>
&nbsp;
<span class="kw4">int</span> main<span class="br0">&#40;</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
    CyGlobalIntEnable<span class="sy0">;</span>
&nbsp;
    BLEIOT_Start<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    CapSense_Start<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    CapSense_InitializeEnabledBaselines<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    CapSense_ScanEnabledWidgets<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    <span class="kw1">for</span><span class="br0">&#40;</span><span class="sy0">;;</span><span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
        <span class="kw1">if</span><span class="br0">&#40;</span><span class="sy0">!</span>CapSense_IsBusy<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
        <span class="br0">&#123;</span>
            <span class="kw4">uint8</span> b0<span class="sy0">=</span>CapSense_CheckIsWidgetActive<span class="br0">&#40;</span>CapSense_BUTTON0__BTN<span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="kw1">if</span><span class="br0">&#40;</span>b0 <span class="sy0">!=</span> BLEIOT_local.<span class="me1">button0</span><span class="br0">&#41;</span> <span class="co1">// if the state has changed then send an update</span>
                BLEIOT_updateButton0<span class="br0">&#40;</span>b0<span class="br0">&#41;</span><span class="sy0">;</span>
            CapSense_UpdateEnabledBaselines<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            CapSense_ScanEnabledWidgets<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
&nbsp;
        <span class="kw1">if</span><span class="br0">&#40;</span>BLEIOT_getDirtyFlags<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">&amp;</span>amp<span class="sy0">;</span> BLEIOT_FLAG_LED0<span class="br0">&#41;</span>  <span class="co1">// if the PRoC side send an update, write it</span>
        <span class="br0">&#123;</span>
            BLEIOT_updateLed0<span class="br0">&#40;</span>BLEIOT_remote.<span class="me1">led0</span><span class="br0">&#41;</span><span class="sy0">;</span>
            led0_Write<span class="br0">&#40;</span><span class="sy0">!</span>BLEIOT_local.<span class="me1">led0</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// the led is active low</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span>
<span class="br0">&#125;</span>
<span class="sy0">&lt;/</span>project.<span class="me1">h</span><span class="sy0">&gt;</span></pre></div></div></div></div></div></div></div>


<p>&nbsp;</p>
<h2>Debugging using CySmart</h2>
<p>After I created all of the code and bootloaded it into the PRoC I used CySmart to debug it.  Once the board is reset I can see the blinking blue LED that is connected to the PRoC.   When I start CySmart I can see the &#8220;C021&#8221; board (that is the name I gave the device in the Gap settings:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112449.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112449-576x1024.png" alt="Screenshot_20160530-112449" width="576" height="1024" class="alignnone size-large wp-image-1599" srcset="https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112449-576x1024.png 576w, https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112449-600x1067.png 600w, https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112449-169x300.png 169w, https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112449-768x1365.png 768w, https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112449.png 1080w" sizes="(max-width: 576px) 100vw, 576px" /></a></p>
<p>When I connect to the device and explore the Gatt Database I can see the three characteristics (Boatload, LED0 and Button0).  You can recognize them from the UUIDs that I configured in the component.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112358.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112358-576x1024.png" alt="Screenshot_20160530-112358" width="576" height="1024" class="alignnone size-large wp-image-1600" srcset="https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112358-576x1024.png 576w, https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112358-600x1067.png 600w, https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112358-169x300.png 169w, https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112358-768x1365.png 768w, https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112358.png 1080w" sizes="(max-width: 576px) 100vw, 576px" /></a></p>
<p>When I write a 1 into the LED0 characteristic the Green LED0 lights up.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112421.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112421-576x1024.png" alt="Screenshot_20160530-112421" width="576" height="1024" class="alignnone size-large wp-image-1601" srcset="https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112421-576x1024.png 576w, https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112421-600x1067.png 600w, https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112421-169x300.png 169w, https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112421-768x1365.png 768w, https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112421.png 1080w" sizes="(max-width: 576px) 100vw, 576px" /></a></p>
<p>When I turn on notification for the Button0 characteristic and then touch the button I can see it turn back and forth from 0/1</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112435.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112435-576x1024.png" alt="Screenshot_20160530-112435" width="576" height="1024" class="alignnone size-large wp-image-1602" srcset="https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112435-576x1024.png 576w, https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112435-600x1067.png 600w, https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112435-169x300.png 169w, https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112435-768x1365.png 768w, https://iotexpert.com/wp-content/uploads/2016/05/Screenshot_20160530-112435.png 1080w" sizes="(max-width: 576px) 100vw, 576px" /></a></p>
<p>Now that everything seems to be working Ill move onto the iPhone App in the next post.</p>
<p><span><p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >index</th>
<th >description</th>
</tr>
</thead>
<tbody>
<tr><td ><a href="https://iotexpert.com/2016/05/23/cy8ckit-021-a-simple-fmpsoc-ble-demonstration-board/">CY8CKIT-021: A Simple FM/PSoC + BLE Demonstration Board</a></td>
<td >Introduction to CY8CKIT021</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/05/24/cy8ckit-021-the-first-4-example-projects/">CY8CKIT-021: The first four example projects</a></td>
<td >Use the LEDs</td>
<td > Buzzer</td>
<td > 7-Segment display and the Potentiometer</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/05/25/cy8ckit-021-the-next-3-example-projects/">CY8CKIT-021: The next three example projects</a></td>
<td >Use theThermistor and two Capsense Examples</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/06/06/cy8ckit-021-the-proc-ble-firmware/">CY8CKIT-021: Bootloading the PRoC</a></td>
<td >How to put firmware into the PRoC</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/05/31/cy8ckit-021-the-bleiot-component/">CY8CKIT-021: The BLEIOT Component</a></td>
<td >A custom component to communicate with the PRoC/PSoC</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/06/02/cy8ckit-021-using-the-bleiot-component/">CY8CKIT-021: Using the BLEIOT Component</a></td>
<td >A full example of the tho MCUs talking</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/06/06/cy8ckit-021-the-proc-ble-firmware/">CY8CKIT-021: The PRoC BLE Firmware</a></td>
<td >How to make PRoC Firmware and use it with the BLEIOT Component</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/06/13/cy8ckit-021-example-10-the-ios-app/">CY8CKIT-021: Example 10 - the new IOS App</a></td>
<td >How to build and IOS App to talk to the development kit</td>
</tr>
</tbody></table></div></p></span></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/cy8ckit-021-the-proc-ble-firmware/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>CY8CKIT-021: Using the BLEIOT Component</title>
		<link>https://iotexpert.com/cy8ckit-021-using-the-bleiot-component/</link>
					<comments>https://iotexpert.com/cy8ckit-021-using-the-bleiot-component/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Thu, 02 Jun 2016 09:36:15 +0000</pubDate>
				<category><![CDATA[Cy8CKIT-021]]></category>
		<category><![CDATA[DevKits]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=1541</guid>

					<description><![CDATA[Now that we have a component built up, I will build up a test to demonstrate its functionality.  The test will do the following On the PSoC side it will: Read the Capsense Button0.  If it is pressed it will send a &#8220;boatload&#8221; command to the PRoC Read the Capsense Button1.  Each time it is [&#8230;]]]></description>
										<content:encoded><![CDATA[<p lang="c" line="1">Now that we have a <a href="https://iotexpert.com/2016/05/31/cy8ckit-021-the-bleiot-component/" target="_blank">component</a> built up, I will build up a test to demonstrate its functionality.  The test will do the following</p>
<p>On the PSoC side it will:</p>
<ul>
<li lang="c" line="1">Read the Capsense Button0.  If it is pressed it will send a &#8220;boatload&#8221; command to the PRoC</li>
<li lang="c" line="1">Read the Capsense Button1.  Each time it is pressed it will toggle the PRoC blue LED by sending alternating On/Off</li>
<li lang="c" line="1">Read the remote LED0 update and turn on/off the LED0 based on the remote command</li>
</ul>
<p>On the PRoC side it will:</p>
<ul>
<li lang="c" line="1">Alternate sending a 1/0 every 500ms to the &#8220;led0&#8221; on the PSoC side</li>
<li lang="c" line="1">If the Capsense Button 0 is changed from the PSoC side it will turn the Blue LED On/Off</li>
<li lang="c" line="1">If it get a Bootload it will enter the bootloader</li>
</ul>
<p>These projects are available as Example9 in the CY8CKIT-021 workspace that is in the firmware directory on github at <a href="http://github.com/iotexpert/CY8CKIT-021" target="_blank">github.com/iotexpert/CY8CKIT-021</a></p>
<h2>PSoC</h2>
<p>After creating a new schematic for PSoC 4200m, the next thing that I do is make a dependency to the components in the BLEInterface project.  This gives me access to the BLEIOT component.</p>
<p><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-11.56.18-AM.png" alt="Screen Shot 2016-05-28 at 11.56.18 AM" width="581" height="671" class="alignnone size-large wp-image-1565" srcset="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-11.56.18-AM.png 581w, https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-11.56.18-AM-260x300.png 260w" sizes="(max-width: 581px) 100vw, 581px" /></p>
<p>When I go to the component catalog I see the &#8220;IOT&#8221; and in that tab I find the  IOT Tab with the BLEIOT component.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.02.55-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.02.55-PM.png" alt="Screen Shot 2016-05-28 at 12.02.55 PM" width="502" height="352" class="alignnone size-full wp-image-1566" srcset="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.02.55-PM.png 502w, https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.02.55-PM-300x210.png 300w" sizes="(max-width: 502px) 100vw, 502px" /></a></p>
<p>Now I add components for CapSense and the LED to get the final schematic.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.09.56-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.09.56-PM.png" alt="Screen Shot 2016-05-28 at 12.09.56 PM" width="384" height="338" class="alignnone size-full wp-image-1567" srcset="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.09.56-PM.png 384w, https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.09.56-PM-300x264.png 300w" sizes="(max-width: 384px) 100vw, 384px" /></a></p>
<p>Now assign the Pins in the cydwr.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.10.57-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.10.57-PM.png" alt="Screen Shot 2016-05-28 at 12.10.57 PM" width="414" height="173" class="alignnone size-full wp-image-1568" srcset="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.10.57-PM.png 414w, https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.10.57-PM-300x125.png 300w" sizes="(max-width: 414px) 100vw, 414px" /></a></p>
<p>And finally the code:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="c"><pre class="de1"><span class="co1">// Project: Example9b-PSoC-BLEIOT-Test</span>
<span class="co1">// Kit: CY8CKIT-021 Sheild</span>
<span class="co1">// Baseboard: CY8CKit-44 PSoC4M</span>
<span class="co1">//</span>
<span class="co1">// This project demonstrates using the BLEIOT component</span>
<span class="co1">// If the other side writes the LED then update it</span>
<span class="co1">// If the user presses button 0 then send an bootload command</span>
<span class="co1">// If the user presses button 1 then send an update to the button</span>
&nbsp;
<span class="co2">#include &lt;project.h&gt;</span>
&nbsp;
<span class="kw4">int</span> main<span class="br0">&#40;</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
    CyGlobalIntEnable<span class="sy0">;</span> 
    CapSense_Start<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    CapSense_InitializeEnabledBaselines<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    CapSense_ScanEnabledWidgets<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    BLEIOT_Start<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    <span class="kw1">for</span><span class="br0">&#40;</span><span class="sy0">;;</span><span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
        <span class="kw1">if</span><span class="br0">&#40;</span><span class="sy0">!</span>CapSense_IsBusy<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
        <span class="br0">&#123;</span>
            <span class="kw4">uint8</span> b0 <span class="sy0">=</span> CapSense_CheckIsWidgetActive<span class="br0">&#40;</span>CapSense_BUTTON0__BTN<span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="kw4">uint8</span> b1 <span class="sy0">=</span> CapSense_CheckIsWidgetActive<span class="br0">&#40;</span>CapSense_BUTTON1__BTN<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
            <span class="kw1">if</span><span class="br0">&#40;</span>b0<span class="br0">&#41;</span>
                BLEIOT_updateBootload<span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// send the bootload command</span>
&nbsp;
            <span class="kw1">if</span><span class="br0">&#40;</span>b1 <span class="sy0">!=</span> BLEIOT_local.<span class="me1">button1</span><span class="br0">&#41;</span> <span class="co1">// if the button state has changed send it</span>
                BLEIOT_updateButton1<span class="br0">&#40;</span>b1<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
            CapSense_UpdateEnabledBaselines<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            CapSense_ScanEnabledWidgets<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
&nbsp;
        <span class="kw1">if</span><span class="br0">&#40;</span>BLEIOT_getDirtyFlags<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">&amp;</span>amp<span class="sy0">;</span> BLEIOT_FLAG_LED0<span class="br0">&#41;</span> <span class="co1">// other side wrote LED0, update state</span>
        <span class="br0">&#123;</span>
            BLEIOT_updateLed0<span class="br0">&#40;</span>BLEIOT_local.<span class="me1">led0</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// update local state</span>
            led0_Write<span class="br0">&#40;</span><span class="sy0">!</span>BLEIOT_remote.<span class="me1">led0</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// the LED is active low</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span>
<span class="br0">&#125;</span>
<span class="sy0">&lt;/</span>project.<span class="me1">h</span><span class="sy0">&gt;</span></pre></div></div></div></div></div></div></div>


<h2>PRoC</h2>
<p>Unfortunately it is prohibited to create custom components for PRoC BLE devices.  So, the first thing that I do after creating the project is to copy over BLEIOT_BLEIOT.c and BLEIOT_BLEIOT.h from the generated source directory of the PSoC project.  Yes I understand that this is a bit of a lame thing to do, but there it is:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1"><span class="kw3">cd</span> Example9a-ProC-BLEIOT-Test.cydsn<span class="sy0">/</span>
<span class="kw2">cp</span> ..<span class="sy0">/</span>Example9b-PSoC-BLEIOT-Test.cydsn<span class="sy0">/</span>Generated_Source<span class="sy0">/</span>PSoC4<span class="sy0">/</span>BLEIOT_BLEIOT.<span class="sy0">*</span> .</pre></div></div></div></div></div></div></div>


<p>One you have the files in the correct directory you need to add them to the project by right clicking on the &#8220;header files&#8221; in the workspace explorer and &#8220;add existing&#8221; then adding the BLEIOT_BLEIOT.h.  You also should do the same with &#8220;source files&#8221; and BLEIOT_BLEIOT.c</p>
<p>Finally you need to add #include &#8220;BLEIOT_BLEIOT.h&#8221; to the top of BLEIOT_BLEIOT.c</p>
<p>After that I finish the schematic.  First, add a UART Component to the schematic and call it BLEIOT_UART (so that it will match the code that was generated in the other project).  Then add the bootloadable and the blue LED pin.  Don&#8217;t forget to configure the Bootloadable to link to the bootloader just like Example 8.  Also you need to configure the UART to have a 32 byte software buffer.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.40.14-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.40.14-PM.png" alt="Screen Shot 2016-05-28 at 12.40.14 PM" width="600" height="354" class="alignnone size-full wp-image-1574" srcset="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.40.14-PM.png 600w, https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.40.14-PM-300x177.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a></p>
<p>Then assign the pins:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.41.51-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.41.51-PM.png" alt="Screen Shot 2016-05-28 at 12.41.51 PM" width="414" height="107" class="alignnone size-full wp-image-1575" srcset="https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.41.51-PM.png 414w, https://iotexpert.com/wp-content/uploads/2016/05/Screen-Shot-2016-05-28-at-12.41.51-PM-300x78.png 300w" sizes="(max-width: 414px) 100vw, 414px" /></a></p>
<p>Finally the main.c</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="c"><pre class="de1"><span class="co1">// Project: Example9b-PRoC-BLEIOT-Test</span>
<span class="co1">// Kit: CY8CKIT-021 Sheild</span>
<span class="co1">// Baseboard: CY8CKit-44 PSoC4M</span>
<span class="co1">//</span>
<span class="co1">// This project should be bootloaded into the PRoC.  It demonstrates using the BLEIOT</span>
<span class="co1">// component.</span>
<span class="co1">//</span>
<span class="co1">// Using the systick, send an update to led0 every 500ms</span>
<span class="co1">// If the other side writes to Bootload... then start the bootloader</span>
<span class="co1">// If the other side writes to the button1... then display that on the blue led</span>
<span class="co2">#include &lt;project.h&gt;</span>
<span class="co2">#include &quot;BLEIOT_BLEIOT.h&quot;</span>
&nbsp;
<span class="kw4">int</span> countMs <span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span>
&nbsp;
<span class="co1">// This is the ISR for the systick</span>
<span class="kw4">void</span> sendLedUpdate<span class="br0">&#40;</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
    <span class="kw1">if</span><span class="br0">&#40;</span>countMs<span class="sy0">++&amp;</span>lt<span class="sy0">;</span><span class="nu0">500</span><span class="br0">&#41;</span> <span class="co1">// count 500ms</span>
        <span class="kw1">return</span><span class="sy0">;</span>
    countMs <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span>
    BLEIOT_updateLed0<span class="br0">&#40;</span><span class="sy0">!</span>BLEIOT_local.<span class="me1">led0</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="kw4">int</span> main<span class="br0">&#40;</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
&nbsp;
    CyGlobalIntEnable<span class="sy0">;</span> 
    CyDelay<span class="br0">&#40;</span><span class="nu0">100</span><span class="br0">&#41;</span><span class="sy0">;</span>
    BLEIOT_Start<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    CySysTickStart<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// start the systick and register our call back</span>
    CySysTickSetCallback<span class="br0">&#40;</span><span class="nu0">0</span><span class="sy0">,</span>sendLedUpdate<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    <span class="kw1">for</span><span class="br0">&#40;</span><span class="sy0">;;</span><span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
&nbsp;
        <span class="kw1">if</span><span class="br0">&#40;</span>BLEIOT_getDirtyFlags<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">&amp;</span>amp<span class="sy0">;</span> BLEIOT_FLAG_BOOTLOAD<span class="br0">&#41;</span>
            Bootloadable_Load<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
        <span class="kw1">if</span><span class="br0">&#40;</span>BLEIOT_getDirtyFlags<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">&amp;</span>amp<span class="sy0">;</span> BLEIOT_FLAG_BUTTON1<span class="br0">&#41;</span>
        <span class="br0">&#123;</span>
            BLEIOT_updateButton1<span class="br0">&#40;</span>BLEIOT_remote.<span class="me1">button1</span><span class="br0">&#41;</span><span class="sy0">;</span>
            blue_Write<span class="br0">&#40;</span><span class="sy0">!</span>BLEIOT_local.<span class="me1">button1</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span>
<span class="br0">&#125;</span>
<span class="sy0">&lt;/</span>project.<span class="me1">h</span><span class="sy0">&gt;</span></pre></div></div></div></div></div></div></div>


<p>&nbsp;</p>
<p>As always these projects are available in the firmware directory at <a href="http://github.com/iotexpert/CY8CKIT-021" target="_blank">http://github.com/iotexpert/CY8CKIT-021</a></p>
<p>In the next post Ill show you the BLE Firmware.</p>
<p><span><p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >index</th>
<th >description</th>
</tr>
</thead>
<tbody>
<tr><td ><a href="https://iotexpert.com/2016/05/23/cy8ckit-021-a-simple-fmpsoc-ble-demonstration-board/">CY8CKIT-021: A Simple FM/PSoC + BLE Demonstration Board</a></td>
<td >Introduction to CY8CKIT021</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/05/24/cy8ckit-021-the-first-4-example-projects/">CY8CKIT-021: The first four example projects</a></td>
<td >Use the LEDs</td>
<td > Buzzer</td>
<td > 7-Segment display and the Potentiometer</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/05/25/cy8ckit-021-the-next-3-example-projects/">CY8CKIT-021: The next three example projects</a></td>
<td >Use theThermistor and two Capsense Examples</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/06/06/cy8ckit-021-the-proc-ble-firmware/">CY8CKIT-021: Bootloading the PRoC</a></td>
<td >How to put firmware into the PRoC</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/05/31/cy8ckit-021-the-bleiot-component/">CY8CKIT-021: The BLEIOT Component</a></td>
<td >A custom component to communicate with the PRoC/PSoC</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/06/02/cy8ckit-021-using-the-bleiot-component/">CY8CKIT-021: Using the BLEIOT Component</a></td>
<td >A full example of the tho MCUs talking</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/06/06/cy8ckit-021-the-proc-ble-firmware/">CY8CKIT-021: The PRoC BLE Firmware</a></td>
<td >How to make PRoC Firmware and use it with the BLEIOT Component</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/06/13/cy8ckit-021-example-10-the-ios-app/">CY8CKIT-021: Example 10 - the new IOS App</a></td>
<td >How to build and IOS App to talk to the development kit</td>
</tr>
</tbody></table></div></p></span></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/cy8ckit-021-using-the-bleiot-component/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
