<?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>Project Archives - Digital Me</title>
	<atom:link href="https://ba0sh1.com/category/project/feed/" rel="self" type="application/rss+xml" />
	<link>https://ba0sh1.com/category/project/</link>
	<description>Electronics, Computers at leisure time</description>
	<lastBuildDate>Mon, 11 Jul 2022 04:58:03 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.6</generator>
	<item>
		<title>First sight into ESP32</title>
		<link>https://ba0sh1.com/2015/12/26/first-signt-into-esp32/</link>
					<comments>https://ba0sh1.com/2015/12/26/first-signt-into-esp32/#comments</comments>
		
		<dc:creator><![CDATA[Baoshi]]></dc:creator>
		<pubDate>Fri, 25 Dec 2015 16:32:18 +0000</pubDate>
				<category><![CDATA[Project]]></category>
		<category><![CDATA[ESP31]]></category>
		<category><![CDATA[ESP32]]></category>
		<category><![CDATA[TFT]]></category>
		<guid isPermaLink="false">https://www.ba0sh1.com/?p=1151</guid>

					<description><![CDATA[<p>So I am one of the 200 lucky bastards who receive the Espressif ESP32 beta units. It arrives in a nicely printed packaging which resembles very much like a jewel box. And...</p>
<p>The post <a href="https://ba0sh1.com/2015/12/26/first-signt-into-esp32/">First sight into ESP32</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>So I am one of the 200 lucky bastards who receive the Espressif ESP32 beta units. It arrives in a nicely printed packaging which resembles very much like a jewel box. And the item inside is really a piece of jewelry.</p>
<p><span id="more-1151"></span></p>
<figure id="attachment_1152" aria-describedby="caption-attachment-1152" style="width: 640px" class="wp-caption aligncenter"><img fetchpriority="high" decoding="async" class="wp-image-1152 size-full" src="https://ba0sh1.com/wp-content/uploads/2015/12/3df35-esp31-box.png" alt="ESP31 packaging" width="640" height="480" srcset="https://ba0sh1.com/wp-content/uploads/2015/12/3df35-esp31-box.png 640w, https://ba0sh1.com/wp-content/uploads/2015/12/3df35-esp31-box-300x225.png 300w" sizes="(max-width: 640px) 100vw, 640px" /><figcaption id="caption-attachment-1152" class="wp-caption-text">ESP31 packaging</figcaption></figure>
<p>Appearantly the breakout board, &#8220;ESP_Module_Testboard&#8221;, is little bit too wide for breadboard use, (leaving one row on each side), I decided to make a quick development board. The end result looks like this.</p>
<figure id="attachment_1154" aria-describedby="caption-attachment-1154" style="width: 800px" class="wp-caption aligncenter"><img decoding="async" class="wp-image-1154 size-full" src="https://ba0sh1.com/wp-content/uploads/2015/12/c1fb2-esp31-devboard.png" alt="ESP31 development board" width="800" height="600" srcset="https://ba0sh1.com/wp-content/uploads/2015/12/c1fb2-esp31-devboard.png 800w, https://ba0sh1.com/wp-content/uploads/2015/12/c1fb2-esp31-devboard-300x225.png 300w, https://ba0sh1.com/wp-content/uploads/2015/12/c1fb2-esp31-devboard-768x576.png 768w" sizes="(max-width: 800px) 100vw, 800px" /><figcaption id="caption-attachment-1154" class="wp-caption-text">ESP31 development board</figcaption></figure>
<p>Some notes about the board:</p>
<ul>
<li>Pin &#8220;EN&#8221; has a 10k pull-up resistor. The reset button pulls &#8220;EN&#8221; down. ESP31 does not come with a RESET pin, it seems EN does the same.</li>
<li>Pin &#8220;IO0&#8221; has a 10k pull-up resistor. The &#8220;IO0&#8221; pin pulls it down. Low level on IO0 during reset allows the ESP31 to enter programming mode. This is very much the same as ESP8266. I am not sure if the pull-up resistor is needed because it seems there is one built-in. Nevertheless I just put one for safety reason.</li>
<li>The red board is a FTDI USB-Serial converter. The board is set to 3.3V I/O. The orange color jumper wire from FTDI board is to get 5V power from USB, feed through an AMS1117-3.3 to power the ESP31 module. I used a 100uF output tantinium capacitor. It seems this setup is not good enough. I&#8217;ll explain later.</li>
</ul>
<p>With the board on hand, it is now time to setup development environment. There are excellent guides at <a href="http://www.instructables.com/id/Beginners-ESP32-Guide-to-Assembly-Testing/" target="_blank" rel="noopener">http://www.instructables.com/id/Beginners-ESP32-Guide-to-Assembly-Testing/</a>, as well as LadyAda&#8217;s live show <a href="https://www.youtube.com/watch?v=HCGHb0OVz1s" target="_blank" rel="noopener">https://www.youtube.com/watch?v=HCGHb0OVz1s</a></p>
<p>New year is around the corner and I am so eager to continue my new year greeting video &#8220;series&#8221;. It natually envolves into this:</p>
<p>https://youtu.be/6SR7anr_Xi4</p>
<p>And the source code too: <a href="https://github.com/baoshi/ESP32-XMAS" target="_blank" rel="noopener">https://github.com/baoshi/ESP32-XMAS</a></p>
<p>Again some notes about the source code:</p>
<ul>
<li>The TFT screen contains 128&#215;160 pixels, at 16bit/pixel it amounts to 40kB/frame, or 320kbits/frame. The SPI bus is running at 13.3MHz, that works out around 40fps. Due to some coding overhead the fastest I can achieve is about 25fps. But again becaused of the latency at WiFi side, I&#8217;m currently running the screen at 10fps. That is only 400kB/s for WiFi traffic, which is significantly slower than the claimed 140Mb/s rated speed. Of course there is huge room for improvement at software side.</li>
<li>The ESP31 seems to take more power than it&#8217;s predecessor ESP8266. The above mentioned AMS1117-3.3 cannot provide enough juice. The phenomenon is garbaged output from serial port, lost WiFi connection, or failed with exception after reset. It could be a thermal issue. I ended up using a lab power supply then all the problems are gone. My supply registered 170mA when WiFi is active. Of course it includes the LCD comsumption. I will do some further investigation at a later time.</li>
<li>I encouontered some WiFi abnormalities that the connection speed slows down significantly from time to time. Reset the chip will resolve the issue. For the time being I havn&#8217;t fully dig into it.</li>
<li>Other than these, ESP31 (ESP32 Beta) and the current SDK (1.1.0) seems quite stable.</li>
</ul>
<p>To all my readers or viewers I take this oppotunity to wish you a Merry Christmas and Happy New Year. See you next year.</p>
<p>The post <a href="https://ba0sh1.com/2015/12/26/first-signt-into-esp32/">First sight into ESP32</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ba0sh1.com/2015/12/26/first-signt-into-esp32/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>ESP8266 MQTT client on RTOS</title>
		<link>https://ba0sh1.com/2015/08/30/esp8266-mqtt-rtos/</link>
					<comments>https://ba0sh1.com/2015/08/30/esp8266-mqtt-rtos/#comments</comments>
		
		<dc:creator><![CDATA[Baoshi]]></dc:creator>
		<pubDate>Sat, 29 Aug 2015 16:04:49 +0000</pubDate>
				<category><![CDATA[Project]]></category>
		<category><![CDATA[ESP8266]]></category>
		<category><![CDATA[MQTT]]></category>
		<category><![CDATA[RTOS]]></category>
		<guid isPermaLink="false">https://www.ba0sh1.com/?p=1133</guid>

					<description><![CDATA[<p>In the recent Maker Faire I demonstrated an ESP8266 MQTT VFD clock. Some readers had wrote to ask for the soure code. Because the project was builtup within only 2 days, the...</p>
<p>The post <a href="https://ba0sh1.com/2015/08/30/esp8266-mqtt-rtos/">ESP8266 MQTT client on RTOS</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In the recent <a href="https://www.ba0sh1.com/maker-faire-yearly-review-rant/" target="_blank" rel="noopener">Maker Faire</a> I demonstrated an ESP8266 MQTT VFD clock. Some readers had wrote to ask for the soure code. Because the project was builtup within only 2 days, the actual source code is more or less of spaghette type. However the underlying MQTT client may be useful to someone who likes the RTOS SDK.</p>
<p><span id="more-1133"></span></p>
<p>If you search MQTT and ESP8266 on the intraweb, most likely all hits can be traced back to the great work done by TuanPM. However Tuan&#8217;s code is based on Espressif&#8217;s NON-OS SDK. There has been some <a href="http://thesparkgap.net/post/92275918408/the-spark-gap-podcast-episode-4" target="_blank" rel="noopener">great debates</a> about embedded programming with-or-without an OS. To me programming with OS vs NON-OS is like programming with C vs Assembly. I like programming in C, so I wrote a new MQTT client for Espressif&#8217;s <a href="https://github.com/espressif/ESP8266_RTOS_SDK" target="_blank" rel="noopener">RTOS SDK.</a></p>
<p>The source code is published at https://github.com/baoshi/ESP-RTOS-Paho</p>
<p>Here are some notes:</p>
<ul>
<li>The code is based on the <a href="http://www.eclipse.org/paho/" target="_blank" rel="noopener">Eclipse Paho project</a>, specifically the embedded C client.</li>
<li>Socket-level APIs used, the code is thread-safe.</li>
<li>Many error handlings were added to the original Paho client, including time-out for most of the network functions. These are designed to work with an RTOS to support automatic error correction at various abused conditions.</li>
<li>I&#8217;m compiling using the &#8220;<a href="http://programs74.ru/udkew-en.html" target="_blank" rel="noopener">Unofficial ESP8266 DevKit</a>&#8220;. Other toolchain such as <a href="https://github.com/pfalcon/esp-open-sdk" target="_blank" rel="noopener">esp-open-sdk</a> can be used as well (adjust pathes in Makefile).</li>
<li>Skeleton code for connecting a MQTT broker is as follows:</li>
</ul>
<p>[code]<br />
struct Network network;<br />
MQTTClient client = DefaultClient;<br />
MQTTPacket_connectData data = MQTTPacket_connectData_initializer;<br />
unsigned char mqtt_buf[100];<br />
unsigned char mqtt_readbuf[100];</p>
<p>NewNetwork(&amp;network);<br />
ConnectNetwork(&amp;network, MQTT_HOST, MQTT_PORT);<br />
NewMQTTClient(&amp;client, &amp;network, 5000, mqtt_buf, 100, mqtt_readbuf, 100);<br />
data.willFlag = 0;<br />
data.MQTTVersion = 3;<br />
data.clientID.cstring = mqtt_client_id; // you client&#8217;s unique identifier<br />
data.username.cstring = MQTT_USER;<br />
data.password.cstring = MQTT_PASS;<br />
data.keepAliveInterval = 10; // interval for PING message to be sent (seconds)<br />
data.cleansession = 0;<br />
MQTTConnect(&amp;client, &amp;data);<br />
[/code]</p>
<p>To subscribe to a MQTT topic, use</p>
<p>[code]<br />
MQTTSubscribe(&amp;client, &quot;/mytopic&quot;, QOS1, topic_received);<br />
[/code]</p>
<p>The parameter topic_received is a callback function handling the received message:</p>
<p>[code]<br />
// Callback when receiving subscribed message<br />
LOCAL void ICACHE_FLASH_ATTR topic_received(MessageData* md)<br />
{<br />
    int i;<br />
    MQTTMessage* message = md-&gt;message;<br />
    dmsg_puts(&quot;Received Topic &quot;);<br />
    for (i = 0; i t; md-&gt;topic-&gt;lenstring.len; ++i)<br />
        dmsg_putchar(md-&gt;topic-&gt;lenstring.data[i]);<br />
    dmsg_puts(&quot;, Message &quot;);<br />
    for (i = 0; i &lt; (int)message-&gt;payloadlen; ++i)<br />
        dmsg_putchar(((char*)message-&gt;payload)[i]);<br />
    dmsg_puts(&quot;rn&quot;);<br />
}<br />
[/code]</p>
<p>To publish a MQTT topic, use</p>
<p>[code]<br />
char msg[PUB_MSG_LEN];<br />
MQTTMessage message;<br />
message.payload = msg;<br />
message.payloadlen = PUB_MSG_LEN;<br />
message.dup = 0;<br />
message.qos = QOS1;<br />
message.retained = 0;<br />
MQTTPublish(&amp;client, &quot;topic&quot;, &amp;message);<br />
[/code]</p>
<p>The demo project included in the library shows how the MQTT related functions can be organized inside a FreeRTOS task and interact with other tasks, such as retry connection after server error, WiFi error, etc. The following diagram may be helpful to understand the code. (Imaging how this can be done using NON-OS SDK)</p>
<figure id="attachment_1141" aria-describedby="caption-attachment-1141" style="width: 600px" class="wp-caption aligncenter"><img decoding="async" class="wp-image-1141" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/11/28705-mqtt_wifi_threads.png?w=1024&#038;h=576" alt="MQTT and WiFi Thread" width="600" height="337" srcset="https://ba0sh1.com/wp-content/uploads/2015/11/28705-mqtt_wifi_threads.png 1425w, https://ba0sh1.com/wp-content/uploads/2015/11/28705-mqtt_wifi_threads-300x169.png 300w, https://ba0sh1.com/wp-content/uploads/2015/11/28705-mqtt_wifi_threads-1024x576.png 1024w, https://ba0sh1.com/wp-content/uploads/2015/11/28705-mqtt_wifi_threads-768x432.png 768w" sizes="(max-width: 600px) 100vw, 600px" /><figcaption id="caption-attachment-1141" class="wp-caption-text">MQTT and WiFi Thread</figcaption></figure>
<p>As Espressif had just teased us with the new ESP32 chip and RTOS is rumored to be the default SDK, I hope this piece of code will be useful.</p>
<p>&nbsp;</p>
<p>The post <a href="https://ba0sh1.com/2015/08/30/esp8266-mqtt-rtos/">ESP8266 MQTT client on RTOS</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ba0sh1.com/2015/08/30/esp8266-mqtt-rtos/feed/</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
			</item>
		<item>
		<title>TrueSTUDIO STM32 project to GCC Makefile converter</title>
		<link>https://ba0sh1.com/2015/04/30/truestudio-stm32-project-to-gcc-makefile-converter/</link>
					<comments>https://ba0sh1.com/2015/04/30/truestudio-stm32-project-to-gcc-makefile-converter/#comments</comments>
		
		<dc:creator><![CDATA[Baoshi]]></dc:creator>
		<pubDate>Thu, 30 Apr 2015 09:25:07 +0000</pubDate>
				<category><![CDATA[Project]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[GCC]]></category>
		<category><![CDATA[Makefile]]></category>
		<category><![CDATA[STM32]]></category>
		<guid isPermaLink="false">https://www.ba0sh1.com/?p=1087</guid>

					<description><![CDATA[<p>Since I wrote the STM32CubeMX to Makefile converter, a lot of people have been helping to improve the project. Thanks! Meanwhile I also heard a lot of complaints about the quality of STM32Cube...</p>
<p>The post <a href="https://ba0sh1.com/2015/04/30/truestudio-stm32-project-to-gcc-makefile-converter/">TrueSTUDIO STM32 project to GCC Makefile converter</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Since I wrote the <a title="STM32CubeMX GCC Makefile project" href="https://www.ba0sh1.com/stm32cubemx-gcc-makefile/" target="_blank" rel="noopener">STM32CubeMX to Makefile converter</a>, a lot of people have been helping to improve the project. Thanks! Meanwhile I also heard a lot of complaints about the quality of STM32Cube codes, for example, the thread <a title="ST's (STM32Cube) software ecosystem is terrible - how can we fix it?" href="http://www.eevblog.com/forum/microcontrollers/st's-(stm32cube)-software-ecosystem-is-terrible-how-can-we-fix-it/" target="_blank" rel="noopener">here</a>. Although I believe STM32Cube&#8217;s quality will eventually improve, at the moment there are still applications for the good old &#8220;Standard Peripheral Library&#8221; and other ST middlewares. Therefore I wrote another program, that converts most of ST&#8217;s example project into Makefile project.<span id="more-1087"></span></p>
<p>The new utility, named ST2Makefile, is available on <a title="ST2Makefile" href="https://github.com/baoshi/ST2Makefile" target="_blank" rel="noopener">https://github.com/baoshi/ST2Makefile</a></p>
<p>My limited testing shows it works for most example projects in ST&#8217;s library package, as well as STM32CubeMX exported projects. One thing needs tweaking could be that some ST&#8217;s example project contains duplicated source files. If you receive error message such as &#8220;Symbol already defined in XXX&#8221; during linking, please check the SRCS section for any duplicated source entries.</p>
<p>The usage is changed a little since CubeMX2Makefile.py, now you should run:</p>
<p>[code light=&#8221;true&#8221;]<br />
ST2Makefile.py &lt;TrueSTUDIO project location&gt;<br />
[/code]</p>
<p>where you can identify TrueSTUDIO project location by locating &#8220;.project&#8221; and &#8220;.cproject&#8221; files inside it.</p>
<p>&nbsp;</p>
<p>As usual, some useful resources:</p>
<h3>Useful links</h3>
<p>ST2Makefile: <a title="ST2Makefile" href="https://github.com/baoshi/ST2Makefile" target="_blank" rel="noopener">https://github.com/baoshi/ST2Makefile</a><br />
ARM GCC: <a title="https://launchpad.net/gcc-arm-embedded" href="https://launchpad.net/gcc-arm-embedded" target="_blank" rel="noopener">https://launchpad.net/gcc-arm-embedded</a></p>
<p>My packaged GNU Make for Win32: <a title="GNU Make Win32" href="https://ba0sh1com.files.wordpress.com/2020/09/2c1c9-make.zip" target="_blank" rel="noopener">https://ba0sh1com.files.wordpress.com/2020/09/2c1c9-make.zip</a></p>
<p>The post <a href="https://ba0sh1.com/2015/04/30/truestudio-stm32-project-to-gcc-makefile-converter/">TrueSTUDIO STM32 project to GCC Makefile converter</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ba0sh1.com/2015/04/30/truestudio-stm32-project-to-gcc-makefile-converter/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>STM32CubeMX GCC Makefile project</title>
		<link>https://ba0sh1.com/2015/02/23/stm32cubemx-gcc-makefile/</link>
					<comments>https://ba0sh1.com/2015/02/23/stm32cubemx-gcc-makefile/#comments</comments>
		
		<dc:creator><![CDATA[Baoshi]]></dc:creator>
		<pubDate>Sun, 22 Feb 2015 18:15:48 +0000</pubDate>
				<category><![CDATA[Project]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[GCC]]></category>
		<category><![CDATA[Makefile]]></category>
		<category><![CDATA[STM32]]></category>
		<category><![CDATA[STM32Cube]]></category>
		<category><![CDATA[STM32CubeMX]]></category>
		<guid isPermaLink="false">https://www.ba0sh1.com/?p=1062</guid>

					<description><![CDATA[<p>Writing peripheral initialization code is probably the most tedious work in embedded development. It always successfully stops me from starting a new project. I believe engineers at STMicroelectronics share the same pain. Therefore...</p>
<p>The post <a href="https://ba0sh1.com/2015/02/23/stm32cubemx-gcc-makefile/">STM32CubeMX GCC Makefile project</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Writing peripheral initialization code is probably the most tedious work in embedded development. It always successfully stops me from starting a new project. I believe engineers at STMicroelectronics share the same pain. Therefore they created <a title="STM32Cube" href="http://www.st.com/stm32cube" target="_blank" rel="noopener">STM32Cube</a> firmware and STM32CubeMX graphical configuration tool, which turns numerous key strokes and page flips into just a few mouse clicks. STM32CubeMX is free software, but the initialization code it generates require compiler tools carrying hefty price tags, IARARM, Keil ARM-MDK, and Atollic TrueSTUDIO, to name the few. Fair enough these compilers do offer free editions with limited functionality. But I still prefer unrestricted, free tool that is easily scale-able for my current and future projects. Just like the GNU Make and ARM GCC toolchain I described in <a title="Opensource STM32 development" href="https://www.ba0sh1.com/opensource-stm32-development/" target="_blank" rel="noopener">Opensource STM32 development</a>.</p>
<p><span id="more-1062"></span></p>
<h2><span style="color:#ff0000;">UPDATE</span></h2>
<p><span style="color:#ff0000;">Always get update from https://github.com/baoshi/CubeMX2Makefile The code is now based on SW4STM32 project output. Thanks various contributors to make this possible.</span></p>
<p>Deprived off electronics lab back in Singapore, a Chinese new year holiday here in Shanghai home is perfect for some software projects. I have little exposure with Python but after two days of Googling (through VPN) and copy/paste, a crude CubeMX2Makefile utility is ready, available at https://github.com/baoshi/CubeMX2Makefile (OOP aficionados please forgive my spaghetti styled code. It works is it?)</p>
<p>As the name suggests, the program converts STM32CubeMX project into a GNU Makefile. Here is a mini-HOWTO:</p>
<ol>
<ol>
<li>Create a STM32CubeMX project, configure pins, peripherals and MiddleWare, then edit project settings as follows: <span style="color:#ff0000;">(choose SW4STM32 instead of TrueStudio in the picture below)</span>
<figure id="attachment_1065" aria-describedby="caption-attachment-1065" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/02/897a8-stm32cubemx_project_setting.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-1065" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/02/897a8-stm32cubemx_project_setting.png?w=1024&#038;h=512" alt="STM32CubeMX project settings" width="600" height="300" srcset="https://ba0sh1.com/wp-content/uploads/2015/02/897a8-stm32cubemx_project_setting.png 1220w, https://ba0sh1.com/wp-content/uploads/2015/02/897a8-stm32cubemx_project_setting-300x150.png 300w, https://ba0sh1.com/wp-content/uploads/2015/02/897a8-stm32cubemx_project_setting-1024x512.png 1024w, https://ba0sh1.com/wp-content/uploads/2015/02/897a8-stm32cubemx_project_setting-768x384.png 768w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-1065" class="wp-caption-text">STM32CubeMX project settings</figcaption></figure>
<p>Make sure the Tool/IDE selection is TrueSTUDIO 4.3.1 (as of STM32CubeMX 4.6.0), and note down the &#8220;Toolchain Folder Location&#8221;. I found it necessary to empty the old &#8220;Toolchain Folder&#8221; before each code generation, otherwise the project file just keep growing regardless of settings (this could be a bug in STM32CubeMX). See <a href="#update">update</a> below.</li>
<li>Download the project from the Github repo below, extract files to a folder, say &#8220;C:CubeMX2Makefile&#8221;. Install Python 2.7 Win32 from www.python.org
<p>[code light=&#8221;true&#8221;]<br />
c:CubeMX2Makefile&gt;dir /b<br />
.gitattributes<br />
.gitignore<br />
CubeMX2Makefile.py<br />
CubeMX2Makefile.tpl<br />
readme.md<br />
[/code]</p>
</li>
<li>From command prompt, execute CubeMX2Makefile.py, e.g,
<p>[code light=&#8221;true&#8221;]<br />
c:CubeMX2Makefile&gt;CubeMX2Makefile.py R:411ProjTestF4<br />
File created: R:411ProjTestF4Makefile<br />
[/code]</p>
</li>
<li>Cd into &#8220;Toolchain Folder Locaiton&#8221;, make project, i.e.,
<p>[code light=&#8221;true&#8221;]<br />
R:411ProjTestF4&gt;make<br />
&#8230;<br />
arm-none-eabi-size build/TestF4.elf<br />
 text data bss dec hex filename<br />
 5876 12 1056 6944 1b20 build/TestF4.elf<br />
arm-none-eabi-objcopy -O ihex build/TestF4.elf build/TestF4.hex<br />
[/code]</p>
<p>Refer to <a title="Command line tools" href="https://www.ba0sh1.com/opensource-stm32-development/#commandlinetools" target="_blank" rel="noopener">blog</a> and below links for ARM GCC and make utility installation. It will be much easier to import the Makefile project into Eclipse CDT for code editing and debugging.</li>
</ol>
</ol>
<h3>Useful links</h3>
<p>CubeMX2Makefile: <a title="https://github.com/baoshi/CubeMX2Makefile" href="https://github.com/baoshi/CubeMX2Makefile" target="_blank" rel="noopener">https://github.com/baoshi/CubeMX2Makefile</a></p>
<p>STM32Cube: <a title="http://www.st.com/stm32cube" href="http://www.st.com/stm32cube" target="_blank" rel="noopener">http://www.st.com/stm32cube</a></p>
<p>ARM GCC: <a title="https://launchpad.net/gcc-arm-embedded" href="https://launchpad.net/gcc-arm-embedded" target="_blank" rel="noopener">https://launchpad.net/gcc-arm-embedded</a></p>
<p>My packaged GNU Make for Win32: <a title="GNU Make Win32" href="https://ba0sh1com.files.wordpress.com/2020/09/2c1c9-make.zip" target="_blank" rel="noopener">https://ba0sh1com.files.wordpress.com/2020/09/2c1c9-make.zip</a></p>
<p><a name="update"></a></p>
<p>&nbsp;</p>
<p>The post <a href="https://ba0sh1.com/2015/02/23/stm32cubemx-gcc-makefile/">STM32CubeMX GCC Makefile project</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ba0sh1.com/2015/02/23/stm32cubemx-gcc-makefile/feed/</wfw:commentRss>
			<slash:comments>36</slash:comments>
		
		
			</item>
		<item>
		<title>ESP8266 breadboard adapter and I&#8217;m on Tindie</title>
		<link>https://ba0sh1.com/2015/01/31/esp8266-breakout-board-im-tindie/</link>
					<comments>https://ba0sh1.com/2015/01/31/esp8266-breakout-board-im-tindie/#comments</comments>
		
		<dc:creator><![CDATA[Baoshi]]></dc:creator>
		<pubDate>Sat, 31 Jan 2015 15:45:54 +0000</pubDate>
				<category><![CDATA[Project]]></category>
		<category><![CDATA[ESP8266]]></category>
		<category><![CDATA[Tindie]]></category>
		<guid isPermaLink="false">https://www.ba0sh1.com/?p=1039</guid>

					<description><![CDATA[<p>The rise of the ESP8266 WiFi chip was almost overnight with Espressif&#8217;s open approach and pushing from Hackaday. While no ground-breaking product has yet emerged, the development on the chip are phenomenon....</p>
<p>The post <a href="https://ba0sh1.com/2015/01/31/esp8266-breakout-board-im-tindie/">ESP8266 breadboard adapter and I&#8217;m on Tindie</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The rise of the ESP8266 WiFi chip was almost overnight with Espressif&#8217;s open approach and pushing from Hackaday. While no ground-breaking product has yet emerged, the <a title="http://www.esp8266.com" href="http://www.esp8266.com" target="_blank" rel="noopener">development </a>on the chip are phenomenon. However due to an unknown reason the ESP8266 <a title="ESP8266 modules family" href="http://www.esp8266.com/wiki/doku.php?id=esp8266-module-family" target="_blank" rel="noopener">modules </a>manufacture seems to prefer non-standard 2.0mm pitch connector, which gives a lot of headache to breadboarding lovers like me. This forced me to make a breadboard friendly ESP8266 breakout board.</p>
<p><span id="more-1039"></span></p>
<p>The modules I&#8217;m targeting are ESP-07 and ESP-12, both having identical pinout but only differ in antenna type. I choose these two because they have all the I/O available, and using same edge castellation (half vias) connectors which is easy to work with.</p>
<figure id="attachment_1042" aria-describedby="caption-attachment-1042" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/4f4fc-esp-07_12.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-1042" src="https://www.ba0sh1.com/wp-content/uploads/2015/01/ESP-07_12-1024x350.png" alt="ESP-07 and ESP-12" width="600" height="206" /></a><figcaption id="caption-attachment-1042" class="wp-caption-text">ESP-07 and ESP-12</figcaption></figure>
<p>The modules are 16mm tall, easily occupies 4 rows (2 rows on each side) on a breadboard. Therefore my first design requirement is to minimize real estate on the breadboard. To do this I made some custom pin headers by modifying from SMT pin header.</p>
<figure id="attachment_1043" aria-describedby="caption-attachment-1043" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/cbd8a-esp-breakout-pinheaders.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-1043" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/cbd8a-esp-breakout-pinheaders.png" alt="Custom pin headers" width="600" height="416" srcset="https://ba0sh1.com/wp-content/uploads/2015/01/cbd8a-esp-breakout-pinheaders.png 800w, https://ba0sh1.com/wp-content/uploads/2015/01/cbd8a-esp-breakout-pinheaders-300x208.png 300w, https://ba0sh1.com/wp-content/uploads/2015/01/cbd8a-esp-breakout-pinheaders-768x533.png 768w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-1043" class="wp-caption-text">Custom pin headers</figcaption></figure>
<p>I removed pair of pins from both ends and replace with through hole pins. This little touch strengthens the bounding between pin header and the board. If otherwise on my first version I can easily pull up all the pads when lifting the board up from breadboard. With this design, I maintain 4 rows occupation on the breadboard, that leaves another 6 rows for wiring.</p>
<figure id="attachment_1044" aria-describedby="caption-attachment-1044" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/299f6-esp-breakout1.jpg" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-1044" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/299f6-esp-breakout1.jpg?w=1024&#038;h=683" alt="Breadboard occupation" width="600" height="400" srcset="https://ba0sh1.com/wp-content/uploads/2015/01/299f6-esp-breakout1.jpg 1280w, https://ba0sh1.com/wp-content/uploads/2015/01/299f6-esp-breakout1-300x200.jpg 300w, https://ba0sh1.com/wp-content/uploads/2015/01/299f6-esp-breakout1-1024x683.jpg 1024w, https://ba0sh1.com/wp-content/uploads/2015/01/299f6-esp-breakout1-768x512.jpg 768w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-1044" class="wp-caption-text">Breadboard occupation</figcaption></figure>
<p>The boot mode of ESP-8266 is often another source of confusion. The table below summarizes different boot modes during power on or reset:</p>
<table style="height:115px;" width="297">
<tbody>
<tr>
<td>Boot Mode</td>
<td>CH_PD</td>
<td>GPIO15</td>
<td>GPIO0</td>
</tr>
<tr>
<td>Run firmware</td>
<td>High</td>
<td>Low</td>
<td>HiZ (Internal P-UP)</td>
</tr>
<tr>
<td>Flash firmware</td>
<td>High</td>
<td>Low</td>
<td>Low</td>
</tr>
</tbody>
</table>
<p>In firmware flashing mode, user is able to update new firmware from UART0 using FLASH_DOWNLOAD_TOOLS or esptool.py.</p>
<p>The board is designed for ESP8266 developers so reset and flash must be made easily accessible. I designed a simple circuit that only uses one button to perform these two tasks:</p>
<figure id="attachment_1047" aria-describedby="caption-attachment-1047" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/d3fd0-esp8266-boot-select-sch.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-1047" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/d3fd0-esp8266-boot-select-sch.png" alt="Boot mode selection schematic" width="600" height="442" srcset="https://ba0sh1.com/wp-content/uploads/2015/01/d3fd0-esp8266-boot-select-sch.png 800w, https://ba0sh1.com/wp-content/uploads/2015/01/d3fd0-esp8266-boot-select-sch-300x221.png 300w, https://ba0sh1.com/wp-content/uploads/2015/01/d3fd0-esp8266-boot-select-sch-768x565.png 768w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-1047" class="wp-caption-text">Boot mode selection schematic</figcaption></figure>
<p>During idle state, internal pull-up in the ESP8266 RESET pin turns on Q1. Q2 cut off so GPIO0 remains high due to GPIO0 internal pull-up. At the same time, C1 discharges from R2 and Q1. When user presses SW1, RESET goes low immediately. Meanwhile, Q1 turns off and 3.3V power charges C1 through R1 and R2. If user releases SW1 quickly and the voltage across C1 has not reached Q2&#8217;s threshold voltage, Q2 remains off and ESP8266 enters normal running mode. However if user holds SW1 long enough before releasing, Q2 will turn on, pull GPIO0 low. At the moment user releases SW1, RESET goes high but GPIO0 will be held low for a while due to C1 have to discharge through R2 and Q1. The choice of C1 and R2 are such that it keeps GPIO0 low long enough for ESP8266 to enter program mode.</p>
<p>The board also includes a 3.3V LDO (AMS-1117 3.3) and a UART header using FTDI Basic pin out. Below is my programming hardware. (Yes I&#8217;m writing OLED driver, which will be release right after).</p>
<figure id="attachment_1048" aria-describedby="caption-attachment-1048" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/a63bf-esp8266-breakout-in-action.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-1048" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/a63bf-esp8266-breakout-in-action.png" alt="ESP8266 breakout board in action" width="600" height="243" srcset="https://ba0sh1.com/wp-content/uploads/2015/01/a63bf-esp8266-breakout-in-action.png 800w, https://ba0sh1.com/wp-content/uploads/2015/01/a63bf-esp8266-breakout-in-action-300x122.png 300w, https://ba0sh1.com/wp-content/uploads/2015/01/a63bf-esp8266-breakout-in-action-768x311.png 768w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-1048" class="wp-caption-text">ESP8266 breakout board in action</figcaption></figure>
<p>The schematic and board are designed using KiCad BZR 5312. Windows binary is available at <a title="http://kicad.nosoftware.cz/" href="http://kicad.nosoftware.cz/" target="_blank" rel="noopener">http://kicad.nosoftware.cz/</a>. I have uploaded the schematic and PCB onto my GitHub page at</p>
<p><a title="https://github.com/baoshi/ESP-Breakout" href="https://github.com/baoshi/ESP-Breakout" target="_blank" rel="noopener">https://github.com/baoshi/ESP-Breakout</a></p>
<p>At the moment I&#8217;m trying to sell extra boards on Tindie. Please visit my store</p>
<p><a href="https://www.tindie.com/stores/Ba0sh1/?ref=offsite_badges&amp;utm_source=sellers_Ba0sh1&amp;utm_medium=badges&amp;utm_campaign=badge_medium"><img loading="lazy" decoding="async" src="https://d2ss6ovg47m0r5.cloudfront.net/badges/tindie-mediums.png" alt="I sell on Tindie" width="150" height="78" /></a></p>
<p>&nbsp;</p>
<p>Product link -&gt; <a title="https://www.tindie.com/products/Ba0sh1/esp8266-esp-0712-full-io-breadboard-adapter/" href="https://www.tindie.com/products/Ba0sh1/esp8266-esp-0712-full-io-breadboard-adapter/" target="_blank" rel="noopener">https://www.tindie.com/products/Ba0sh1/esp8266-esp-0712-full-io-breadboard-adapter/</a></p>
<p>This is my first attempt to generate some income via hobbyist project. Please support if you also want to join the ESP8266 fun!</p>
<p>Thanks</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The post <a href="https://ba0sh1.com/2015/01/31/esp8266-breakout-board-im-tindie/">ESP8266 breadboard adapter and I&#8217;m on Tindie</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ba0sh1.com/2015/01/31/esp8266-breakout-board-im-tindie/feed/</wfw:commentRss>
			<slash:comments>27</slash:comments>
		
		
			</item>
		<item>
		<title>Macbook Bluetooth upgrade for LightBlue Bean</title>
		<link>https://ba0sh1.com/2015/01/15/bluetooth-upgrade-lightblue-bean/</link>
					<comments>https://ba0sh1.com/2015/01/15/bluetooth-upgrade-lightblue-bean/#comments</comments>
		
		<dc:creator><![CDATA[Baoshi]]></dc:creator>
		<pubDate>Wed, 14 Jan 2015 16:18:45 +0000</pubDate>
				<category><![CDATA[Diary]]></category>
		<category><![CDATA[Project]]></category>
		<category><![CDATA[BCM94360CS2]]></category>
		<category><![CDATA[BLE]]></category>
		<category><![CDATA[Bluetooth 4.0]]></category>
		<category><![CDATA[LightBlue Bean]]></category>
		<category><![CDATA[Macbook Air]]></category>
		<guid isPermaLink="false">https://www.ba0sh1.com/?p=1024</guid>

					<description><![CDATA[<p>During last year&#8217;s blackfriday sale I was introduced to the epic Lightblue Bean &#8220;Cheaper than a turkey&#8221; promotion. I grabbed two beans during a group buy spree. A week later&#8217;s The AmpHour interview with...</p>
<p>The post <a href="https://ba0sh1.com/2015/01/15/bluetooth-upgrade-lightblue-bean/">Macbook Bluetooth upgrade for LightBlue Bean</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>During last year&#8217;s blackfriday sale I was introduced to the epic L<a title="Lightblue Bean" href="https://punchthrough.com/bean/" target="_blank" rel="noopener">ightblue Bean</a> &#8220;Cheaper than a turkey&#8221; promotion. I grabbed two beans during a group buy spree. A week later&#8217;s The AmpHour <a title="The AmpHour EP226" href="http://www.theamphour.com/226-an-interview-with-colin-karpfinger-blendling-bean-brio/" target="_blank" rel="noopener">interview with Colin Karpfinger</a> justifies that my purchase is not purely impulsive. However I did make a mistake. I was under the impression that a Mac computer is sufficient to program the bean, but actually only recently Macs are supported, whereas my &#8220;Late 2010&#8221; Macbook Air is on the exclusion list due to the lack of Bluetooth 4.0 / Low Energy profile.</p>
<p><span id="more-1024"></span></p>
<p>Digging into BLE upgrade for Macbook Air Late 2010 results in many solutions. The best resource seems to be the &#8220;<a title="Continuity-Activation-Tool" href="https://github.com/dokterdok/Continuity-Activation-Tool/" target="_blank" rel="noopener">Continuity-Activation-Tool</a>&#8221; project, which is made to enable &#8220;Continuity&#8221; feature on old Mac computers. Since &#8220;Continuity&#8221; depends on BLE, I suppose this will work with Lightblue Bean. For my model of Macbook, the suggestion is either to add a USB dongle or replace the Airport Extreme card. My poor Macbook only has two USB ports, so replace the Airport Extreme card seems to be the way to go.</p>
<p>The suitable replacement Airport Extreme card with BLE is BCM94360CS2. It can be purchased from eBay or Taobao at reasonable price (~US$20). The kind seller also included a Pentalobe screw driver in the package, which proves to be a life saver later.</p>
<figure id="attachment_1025" aria-describedby="caption-attachment-1025" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/abf13-bcm94360cs2.jpg" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-1025" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/abf13-bcm94360cs2.jpg" alt="BCM94360CS2" width="600" height="450" srcset="https://ba0sh1.com/wp-content/uploads/2015/01/abf13-bcm94360cs2.jpg 800w, https://ba0sh1.com/wp-content/uploads/2015/01/abf13-bcm94360cs2-300x225.jpg 300w, https://ba0sh1.com/wp-content/uploads/2015/01/abf13-bcm94360cs2-768x576.jpg 768w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-1025" class="wp-caption-text">BCM94360CS2</figcaption></figure>
<p>For record purpose here are the screenshot of Bluetooth and WiFi page in &#8220;System Information&#8221; before replacement:</p>
<figure id="attachment_1026" aria-describedby="caption-attachment-1026" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/3065a-bt-after-replacement.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-1026" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/3065a-bt-after-replacement.png" alt="Bluetooth before card replacement" width="600" height="439" srcset="https://ba0sh1.com/wp-content/uploads/2015/01/3065a-bt-after-replacement.png 863w, https://ba0sh1.com/wp-content/uploads/2015/01/3065a-bt-after-replacement-300x220.png 300w, https://ba0sh1.com/wp-content/uploads/2015/01/3065a-bt-after-replacement-768x562.png 768w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-1026" class="wp-caption-text">Bluetooth before card replacement</figcaption></figure>
<figure id="attachment_1027" aria-describedby="caption-attachment-1027" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/62664-wifi-before-replacement.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-1027" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/62664-wifi-before-replacement.png" alt="WiFi before card replacement" width="600" height="439" srcset="https://ba0sh1.com/wp-content/uploads/2015/01/62664-wifi-before-replacement.png 863w, https://ba0sh1.com/wp-content/uploads/2015/01/62664-wifi-before-replacement-300x220.png 300w, https://ba0sh1.com/wp-content/uploads/2015/01/62664-wifi-before-replacement-768x562.png 768w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-1027" class="wp-caption-text">WiFi before card replacement</figcaption></figure>
<p>Open the back cover of Macbook Air *REQUIRES* the pentalobe screw driver, and never assume a multi-head screw driver set will contain one.</p>
<p>The original Airport Extreme card has a mouthful BCM943224PCIEBT2 model number. There are two ipx antenna connectors on board, assuming one for Bluetooth and one for WiFi.</p>
<figure id="attachment_1028" aria-describedby="caption-attachment-1028" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/99fd6-bcm943224pciebt2.jpg" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-1028" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/99fd6-bcm943224pciebt2.jpg" alt="BCM943224PCIEBT2" width="600" height="450" srcset="https://ba0sh1.com/wp-content/uploads/2015/01/99fd6-bcm943224pciebt2.jpg 800w, https://ba0sh1.com/wp-content/uploads/2015/01/99fd6-bcm943224pciebt2-300x225.jpg 300w, https://ba0sh1.com/wp-content/uploads/2015/01/99fd6-bcm943224pciebt2-768x576.jpg 768w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-1028" class="wp-caption-text">BCM943224PCIEBT2</figcaption></figure>
<p>My Macbook Air has 11 inch screen. The card placement is different from most online pictures which are for 13inch model. On the 13 inch model the card has longer edge parallel to the casing, but for 11 inch it is perpendicular. It is also reported on many online resources that the antenna cable has to be rerouted to reach the new card. It seems unnecessary for my 11 inch model. I can easily fit the two cables.</p>
<figure id="attachment_1030" aria-describedby="caption-attachment-1030" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/5312b-bcm94360cs2-replaced.jpg" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-1030" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/5312b-bcm94360cs2-replaced.jpg" alt="BCM94360CS2 replaced" width="600" height="450" srcset="https://ba0sh1.com/wp-content/uploads/2015/01/5312b-bcm94360cs2-replaced.jpg 800w, https://ba0sh1.com/wp-content/uploads/2015/01/5312b-bcm94360cs2-replaced-300x225.jpg 300w, https://ba0sh1.com/wp-content/uploads/2015/01/5312b-bcm94360cs2-replaced-768x576.jpg 768w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-1030" class="wp-caption-text">BCM94360CS2 replaced</figcaption></figure>
<p>At the moment I have no idea which antenna is to fit into which socket. But my random connecting seems to be working. Also noted that the new card is longer than the old one, so the mounting hole is no longer fit. However the socket is tight enough to keep the card in place.</p>
<p>I assemble the back cover and turn on power. Not surprisingly everything &#8220;just works&#8221;. No error and no &#8220;install driver&#8221; kinds of message at all. Even the Wireless LAN password and Bluetooth paired devices list are preserved. Here are the system information after replacement:</p>
<figure id="attachment_1031" aria-describedby="caption-attachment-1031" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/82561-bt-after-replacement1.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-1031" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/82561-bt-after-replacement1.png" alt="Bluetooth after card replacement" width="600" height="439" srcset="https://ba0sh1.com/wp-content/uploads/2015/01/82561-bt-after-replacement1.png 863w, https://ba0sh1.com/wp-content/uploads/2015/01/82561-bt-after-replacement1-300x220.png 300w, https://ba0sh1.com/wp-content/uploads/2015/01/82561-bt-after-replacement1-768x562.png 768w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-1031" class="wp-caption-text">Bluetooth after card replacement</figcaption></figure>
<figure id="attachment_1032" aria-describedby="caption-attachment-1032" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/9fc22-wifi-after-replacement.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-1032" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/9fc22-wifi-after-replacement.png" alt="WiFi after card replacement" width="600" height="439" srcset="https://ba0sh1.com/wp-content/uploads/2015/01/9fc22-wifi-after-replacement.png 863w, https://ba0sh1.com/wp-content/uploads/2015/01/9fc22-wifi-after-replacement-300x220.png 300w, https://ba0sh1.com/wp-content/uploads/2015/01/9fc22-wifi-after-replacement-768x562.png 768w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-1032" class="wp-caption-text">WiFi after card replacement</figcaption></figure>
<p>The Bean Loader seems to be happy with the new card as well.</p>
<figure id="attachment_1033" aria-describedby="caption-attachment-1033" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/a2282-bean-loader.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-1033" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2015/01/a2282-bean-loader.png" alt="Bean Loader" width="600" height="369" srcset="https://ba0sh1.com/wp-content/uploads/2015/01/a2282-bean-loader.png 686w, https://ba0sh1.com/wp-content/uploads/2015/01/a2282-bean-loader-300x185.png 300w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-1033" class="wp-caption-text">Bean Loader</figcaption></figure>
<p>As a &#8220;side effect&#8221;, the &#8220;Continuity&#8221; feature works without any tweaking, together with the &#8220;AirDrop&#8221; functionality. The replacement worth every cents of it!</p>
<p>&nbsp;</p>
<p>The post <a href="https://ba0sh1.com/2015/01/15/bluetooth-upgrade-lightblue-bean/">Macbook Bluetooth upgrade for LightBlue Bean</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ba0sh1.com/2015/01/15/bluetooth-upgrade-lightblue-bean/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Happy New Year from ESP8266</title>
		<link>https://ba0sh1.com/2014/12/31/happy-new-year/</link>
					<comments>https://ba0sh1.com/2014/12/31/happy-new-year/#comments</comments>
		
		<dc:creator><![CDATA[Baoshi]]></dc:creator>
		<pubDate>Wed, 31 Dec 2014 13:33:39 +0000</pubDate>
				<category><![CDATA[Diary]]></category>
		<category><![CDATA[Project]]></category>
		<category><![CDATA[ESP8266]]></category>
		<category><![CDATA[OLED]]></category>
		<category><![CDATA[SSD1306]]></category>
		<guid isPermaLink="false">https://www.ba0sh1.com/?p=1016</guid>

					<description><![CDATA[<p>Happy New Year! http://youtu.be/h-lI6ucDg8M The application is made with ESP8266 RTOS SDK. SSD1306 based OLED panel is connected on GPIO4/5 using software emulated I2C. I rushed this out last night and the...</p>
<p>The post <a href="https://ba0sh1.com/2014/12/31/happy-new-year/">Happy New Year from ESP8266</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Happy New Year!</p>
<p><span id="more-1016"></span></p>
<p>http://youtu.be/h-lI6ucDg8M</p>
<p>The application is made with ESP8266<a title="esp_iot_rtos_sdk" href="https://github.com/espressif/esp_iot_rtos_sdk"> RTOS SDK</a>. SSD1306 based OLED panel is connected on GPIO4/5 using software emulated I2C. I rushed this out last night and the code is in a mess now.To prevent bad influence I&#8217;ll release the code after I reorganize them.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The post <a href="https://ba0sh1.com/2014/12/31/happy-new-year/">Happy New Year from ESP8266</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ba0sh1.com/2014/12/31/happy-new-year/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Season&#8217;s Greeting from VFDuino</title>
		<link>https://ba0sh1.com/2014/12/24/seasons-greeting-vfduino/</link>
					<comments>https://ba0sh1.com/2014/12/24/seasons-greeting-vfduino/#respond</comments>
		
		<dc:creator><![CDATA[Baoshi]]></dc:creator>
		<pubDate>Wed, 24 Dec 2014 13:52:16 +0000</pubDate>
				<category><![CDATA[Diary]]></category>
		<category><![CDATA[Project]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[VFD]]></category>
		<guid isPermaLink="false">https://www.ba0sh1.com/?p=1011</guid>

					<description><![CDATA[<p>To all my readers: Wish you a very Merry Christmas. http://youtu.be/aww5O6wBgbw VFDuino, Arduino compatible Vacuum Fluorescent Display module. Open source release imminent.</p>
<p>The post <a href="https://ba0sh1.com/2014/12/24/seasons-greeting-vfduino/">Season&#8217;s Greeting from VFDuino</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>To all my readers:</p>
<p>Wish you a very Merry Christmas.</p>
<p><span id="more-1011"></span></p>
<p>http://youtu.be/aww5O6wBgbw</p>
<p>VFDuino, Arduino compatible Vacuum Fluorescent Display module. Open source release imminent.</p>
<p>The post <a href="https://ba0sh1.com/2014/12/24/seasons-greeting-vfduino/">Season&#8217;s Greeting from VFDuino</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ba0sh1.com/2014/12/24/seasons-greeting-vfduino/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Minimalism AVR development board</title>
		<link>https://ba0sh1.com/2014/10/15/minimalism-avr-development-board/</link>
					<comments>https://ba0sh1.com/2014/10/15/minimalism-avr-development-board/#comments</comments>
		
		<dc:creator><![CDATA[Baoshi]]></dc:creator>
		<pubDate>Wed, 15 Oct 2014 13:29:19 +0000</pubDate>
				<category><![CDATA[Project]]></category>
		<category><![CDATA[Tutorial]]></category>
		<guid isPermaLink="false">https://www.ba0sh1.com/?p=1000</guid>

					<description><![CDATA[<p>Lacking of proper development board always poses huge resistance for me to jump onto a new MCU. Even with the most prototyping friendly DIP packages, wiring a programming header onto the breadboard is both...</p>
<p>The post <a href="https://ba0sh1.com/2014/10/15/minimalism-avr-development-board/">Minimalism AVR development board</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div>
<div style="color:#000000;">Lacking of proper development board always poses huge resistance for me to jump onto a new MCU. Even with the most prototyping friendly DIP packages, wiring a programming header onto the breadboard is both troublesome and unreliable. Things become worse when the MCU is an AVR. There is absolutely no way to mount a 2&#215;3 0.1in pitch programming header onto the breadboard. It was such a pain until recently I found a elegant way to make a quick and dirty minimalism board. Here is how.</div>
</div>
<p><span id="more-1000"></span></p>
<p>The AVR chip I&#8217;m talking about is Atmel ATTiny2313, in SOIC-20 package. To make the development board, I bought some 28 pin SOIC/SSOP to DIP adapters. These adaptors usually come in double sided design. Corresponding pins on both sides are connected via the plated through holes at edges.</p>
<figure id="attachment_1001" aria-describedby="caption-attachment-1001" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2014/10/0b54c-smt_adaptor.jpg" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-1001" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2014/10/0b54c-smt_adaptor.jpg" alt="SOIC/SSOP - DIP adaptor" width="600" height="450" srcset="https://ba0sh1.com/wp-content/uploads/2014/10/0b54c-smt_adaptor.jpg 800w, https://ba0sh1.com/wp-content/uploads/2014/10/0b54c-smt_adaptor-300x225.jpg 300w, https://ba0sh1.com/wp-content/uploads/2014/10/0b54c-smt_adaptor-768x576.jpg 768w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-1001" class="wp-caption-text">SOIC/SSOP &#8211; DIP adaptor</figcaption></figure>
<p>I made a 2&#215;3 AVR programming header by pulling off pins (longer ones) from a double-row right angle pin header and reinsert them into the plastic base. A needle nose pliers is very handy for this purpose.</p>
<figure id="attachment_1002" aria-describedby="caption-attachment-1002" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2014/10/d7ff4-avr_spi_header.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-1002" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2014/10/d7ff4-avr_spi_header.png" alt="AVR programming header" width="600" height="450" srcset="https://ba0sh1.com/wp-content/uploads/2014/10/d7ff4-avr_spi_header.png 800w, https://ba0sh1.com/wp-content/uploads/2014/10/d7ff4-avr_spi_header-300x225.png 300w, https://ba0sh1.com/wp-content/uploads/2014/10/d7ff4-avr_spi_header-768x576.png 768w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-1002" class="wp-caption-text">AVR programming header</figcaption></figure>
<p>Both the programming header and the chip are soldered onto the SOIC side of the adaptor board. The programming header is taking pin 1-3 and 26-28. ATtiny2313 is taking pin 5-14 and 15-24 (numbering according to adaptor board).</p>
<figure id="attachment_1003" aria-describedby="caption-attachment-1003" style="width: 601px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2014/10/a23e0-avr-board-front.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-1003" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2014/10/a23e0-avr-board-front.png" alt="Front side of AVR development board" width="601" height="338" srcset="https://ba0sh1.com/wp-content/uploads/2014/10/a23e0-avr-board-front.png 800w, https://ba0sh1.com/wp-content/uploads/2014/10/a23e0-avr-board-front-300x169.png 300w, https://ba0sh1.com/wp-content/uploads/2014/10/a23e0-avr-board-front-768x432.png 768w" sizes="auto, (max-width: 601px) 100vw, 601px" /></a><figcaption id="caption-attachment-1003" class="wp-caption-text">Front side of AVR development board</figcaption></figure>
<p>Since the corresponding pads at both sides are electrically connect, it is easy to wire the programming header from the back side or the adapter, using enamel wires and some kapton tape. These pads are 0.5mm pitch so a really fine solder tip is necessary (I use Metcal STTC-126).</p>
<figure id="attachment_1004" aria-describedby="caption-attachment-1004" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2014/10/399fe-avr-board-back.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-1004" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2014/10/399fe-avr-board-back.png" alt="Back side of AVR development board" width="600" height="353" srcset="https://ba0sh1.com/wp-content/uploads/2014/10/399fe-avr-board-back.png 800w, https://ba0sh1.com/wp-content/uploads/2014/10/399fe-avr-board-back-300x177.png 300w, https://ba0sh1.com/wp-content/uploads/2014/10/399fe-avr-board-back-768x452.png 768w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-1004" class="wp-caption-text">Back side of AVR development board</figcaption></figure>
<p>Finally install the pins for breadboarding, a minimalism AVR development board is ready to roll. (Picture of ATTiny2313 and ATTiny85 boards below).</p>
<figure id="attachment_1008" aria-describedby="caption-attachment-1008" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2014/10/2b0f0-attiny2313-development-board.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-1008" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2014/10/2b0f0-attiny2313-development-board.png" alt="Minimalism ATTiny2313 development board" width="600" height="450" srcset="https://ba0sh1.com/wp-content/uploads/2014/10/2b0f0-attiny2313-development-board.png 800w, https://ba0sh1.com/wp-content/uploads/2014/10/2b0f0-attiny2313-development-board-300x225.png 300w, https://ba0sh1.com/wp-content/uploads/2014/10/2b0f0-attiny2313-development-board-768x576.png 768w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-1008" class="wp-caption-text">Minimalism ATTiny2313 development board</figcaption></figure>
<p>&nbsp;</p>
<p>The post <a href="https://ba0sh1.com/2014/10/15/minimalism-avr-development-board/">Minimalism AVR development board</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ba0sh1.com/2014/10/15/minimalism-avr-development-board/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>HOWTO: Use STM32 SPI half duplex mode</title>
		<link>https://ba0sh1.com/2014/05/31/howto-use-stm32-spi-half-duplex-mode/</link>
					<comments>https://ba0sh1.com/2014/05/31/howto-use-stm32-spi-half-duplex-mode/#comments</comments>
		
		<dc:creator><![CDATA[Baoshi]]></dc:creator>
		<pubDate>Fri, 30 May 2014 16:11:19 +0000</pubDate>
				<category><![CDATA[Project]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[SPI]]></category>
		<category><![CDATA[STM32]]></category>
		<guid isPermaLink="false">https://www.ba0sh1.com/?p=929</guid>

					<description><![CDATA[<p>I&#8217;ve got my hands onto some STM32F030F4P6 ARM-Cortex M0 processors. Though touted as &#8220;32 cents 32-bit micro&#8221;, it is not that inexpensive from DigiKey in one-off quantity ($1.45). However it is still cheaper...</p>
<p>The post <a href="https://ba0sh1.com/2014/05/31/howto-use-stm32-spi-half-duplex-mode/">HOWTO: Use STM32 SPI half duplex mode</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I&#8217;ve got my hands onto some STM32F030F4P6 ARM-Cortex M0 processors. Though touted as &#8220;32 cents 32-bit micro&#8221;, it is not that inexpensive from DigiKey in one-off quantity ($1.45). However it is still cheaper than ATmegas and offers 3 times the performance. The chip comes in 20-pin TSSOP package. Limited pins require much more thoughts when assigning pin function. For example, using 3-pin half-duplex SPI instead of 4-pin full-duplex SPI saves me 1 very precious GPIO pin. <span id="more-929"></span> It should be noted that not all SPI slave devices support half duplex mode, and most devices will not mention half-duplex mode in the datasheets. Generally, a SPI slave device supports half duplex SPI mode if:</p>
<figure id="attachment_932" aria-describedby="caption-attachment-932" style="width: 600px" class="wp-caption aligncenter"><a href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2014/05/007d0-spi-timing.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="thumbnail wp-image-932" src="https://www.ba0sh1.com/wp-content/uploads/2014/05/SPI-timing-1024x329.png" alt="SPI device supports half-duplex" width="600" height="193" /></a><figcaption id="caption-attachment-932" class="wp-caption-text">SPI device supports half-duplex</figcaption></figure>
<ol>
<li>The device&#8217;s MISO (or DOUT) pin uses open-drain output. This is usually true because open-drain allows multiple SPI slaves to share the same MISO line.</li>
<li>In the communication protocol, the slave device always waits for the master to send fixed number of bytes (commands) from  MOSI, then returns a fixed number of bytes to MISO. Some devices which transmit and receive data simultaneously cannot be used in half-duplex mode.</li>
<li>The slave ignores whatever appears on the MOSI pin when transmitting data to the master. This is usually not mentioned in the datasheet. However, if the slave device mandates a CS or STROBE signal to be asserted at the beginning of each data exchange, we can usually assume this is true. Reason being that the slave device is using CS to reset its internal state rather than always listening and parsing command byte(s) from the master.</li>
</ol>
<p>Half-duplex wiring of STM32 SPI is as follows:</p>
<figure id="attachment_940" aria-describedby="caption-attachment-940" style="width: 600px" class="wp-caption aligncenter"><a href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2014/05/d1990-spi_hd_conn.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="thumbnail wp-image-940" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2014/05/d1990-spi_hd_conn.png" alt="STM32 half-duplex SPI connection" width="600" height="246" srcset="https://ba0sh1.com/wp-content/uploads/2014/05/d1990-spi_hd_conn.png 840w, https://ba0sh1.com/wp-content/uploads/2014/05/d1990-spi_hd_conn-300x123.png 300w, https://ba0sh1.com/wp-content/uploads/2014/05/d1990-spi_hd_conn-768x315.png 768w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-940" class="wp-caption-text">STM32 half-duplex SPI connection</figcaption></figure>
<p>In particular, MOSI and SCK are configured as &#8220;Alternate Function&#8221; mode. Hardware CS (NSS) management must be disabled and user shall manually control CS using GPIO output. R2 is pull-up resistor as required by SPI. R1 works as protection resistor in case STM32 MOSI pin somehow enters into push-pull output mode. The SPI setup code is as follows:</p>
<p>[code]<br />
void SPI_Configure()<br />
{<br />
    SPI_InitTypeDef SPI_InitStructure;<br />
    // Enable SPI1 clock<br />
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);<br />
    // SPI1 configuration<br />
    SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx; // Initially Tx<br />
    SPI_InitStructure.SPI_Mode = SPI_Mode_Master;<br />
    SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;<br />
    SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; // Clock steady high<br />
    SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; // Data write on rising (second) edge<br />
    SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;<br />
    SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;<br />
    SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB;<br />
    SPI_InitStructure.SPI_CRCPolynomial = 7;<br />
    SPI_Init(SPI1, &amp;SPI_InitStructure);<br />
    SPI_RxFIFOThresholdConfig(SPI1, SPI_RxFIFOThreshold_QF);<br />
    SPI_Cmd(SPI1, ENABLE);<br />
}<br />
[/code]</p>
<p>Line 7 sets the SPI peripheral to half-dulex transmission mode. Line 17 sets the SPI FIFO buffer threshold to quarter full. This is new in STM32F0 with 4-byte SPI FIFO buffer. SPI_RxFIFOThreshold_QF meaning that the SPI_I2S_FLAG_RXNE flag will be set as soon as 1 byte (quarter buffer) is shifted into receiving FIFO. SPI master sending data to slave is as simple as:</p>
<p>[code]<br />
void send_byte(uint8_t val)<br />
{<br />
    GPIO_ResetBits(GPIOA, GPIO_Pin_4); // CS low<br />
    while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); //wait buffer empty<br />
    SPI_SendData8(SPI1, val);<br />
    while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET); //wait finish sending<br />
    GPIO_SetBits(GPIOA, GPIO_Pin_4); // CS high<br />
}<br />
[/code]</p>
<p>The following code demonstrates master sends 1 byte command to slave and reads 1 byte back.</p>
<p>[code]<br />
uint8_t send_and_read_byte(uint8_t cmd)<br />
{<br />
    uint8_t result;<br />
    GPIO_ResetBits(GPIOA, GPIO_Pin_4); // CS low<br />
    while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); //wait buffer empty<br />
    SPI_SendData8(SPI1, cmd);<br />
    while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET); //wait finish sending<br />
    // Read receiving FIFO until it is empty<br />
    while (SPI_GetReceptionFIFOStatus(SPI1) != SPI_ReceptionFIFOStatus_Empty)<br />
        SPI_ReceiveData8(SPI1);<br />
    SPI_BiDirectionalLineConfig(SPI1, SPI_Direction_Rx);<br />
    while (!(SPI1-&gt;SR &amp; SPI_I2S_FLAG_RXNE)) ; // wait data received<br />
    GPIO_SetBits(GPIOA, GPIO_Pin_4); // CS high<br />
    SPI1-&gt;CR1 |= SPI_Direction_Tx;  // Set Tx mode to stop Rx clock<br />
    result = SPI_ReceiveData8(SPI1);<br />
    return result;<br />
}<br />
[/code]</p>
<p>Immediately after one byte is sent, the program empties all stale data in the FIFO (line 9, 10), then sets SPI direction to receiving mode (line 11). <em>As soon as SPI enters into receiving mode, STM32 will continuously generate clock on SCK pin until receiving mode is disabled. </em>Along with the clock toggling, data are shifted from MOSI pin into receiving FIFO, and SPI_I2S_FLAG_RXNE flag is set once 1 byte of data is received (line 12). The program then disables CS (line 13, to disable slave output) and switches SPI back to transmitting mode (line 14, to stop the clock). These two steps must be executed fast enough before the next clock is sent out to prevent the slave device enter into any undefined state. Timing is very critical here especially when SPI clock is high. To receive multiple bytes from the slave, put line 9-15 into a loop but disable CS only after all data are read. Important thing is to always disable receiving mode immediately after FIFO is quarter full, and verify using a scope or logic analyser to ensure exact 8 clocks are send in-between each reading.</p>
<p>The post <a href="https://ba0sh1.com/2014/05/31/howto-use-stm32-spi-half-duplex-mode/">HOWTO: Use STM32 SPI half duplex mode</a> appeared first on <a href="https://ba0sh1.com">Digital Me</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ba0sh1.com/2014/05/31/howto-use-stm32-spi-half-duplex-mode/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
	</channel>
</rss>
