<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[MBSBootloader with different CSN&#x2F;CE Pin problem]]></title><description><![CDATA[<p dir="auto">Hello all,</p>
<p dir="auto">I am trying to make a new bootloader where the CSN and CE pins are connected to pin 7 and 8. (CSN = 7 and CE = 8 ).</p>
<p dir="auto">This is what I changed in the bootloader:</p>
<pre><code>// SPI communication

#define SPI_DDR		DDRB
#define SPI_PORT	PORTB
#define SPI_PORT2   PORTD
#define SPI_PIN		PINB
#define	SPI_SCLK	5		// Arduino Pin 13 &lt;-&gt; Bit 5 of port B
#define	SPI_MISO	4		// Arduino Pin 12 &lt;-&gt; Bit 4 of port B
#define	SPI_MOSI	3		// Arduino Pin 11 &lt;-&gt; Bit 3 of port B
#define	SPI_CSN		7		// Arduino Pin 7 &lt;-&gt; Bit 7 of port D
//#define	SPI_CSN		2		// Arduino Pin 10 &lt;-&gt; Bit 2 of port B
#define	SPI_CE		0		// Arduino Pin  8 &lt;-&gt; Bit 0 of port B
//#define	SPI_CE		1		// Arduino Pin  9 &lt;-&gt; Bit 1 of port B
#define CE_PULSE_LENGTH	20	// IMPORTANT: minimum CE pulse width 10us, see nRF24L01 specs. Set 20us to be on the safe side

#define csnlow() DDRD &amp;= ~_BV(SPI_CSN)
#define csnhigh() DDRD |= _BV(SPI_CSN)

#define celow() SPI_PORT &amp;= ~_BV(SPI_CE)
#define cehigh() SPI_PORT |= _BV(SPI_CE)

static void SPIinit() {
	// set pin mode: MOSI,SCLK,CE = OUTPUT, MISO = INPUT
	SPI_DDR = _BV(SPI_MOSI) | _BV(SPI_SCLK) | _BV(SPI_CE) | ~_BV(SPI_MISO);
    // Set CSN = output
	DDRD = _BV(SPI_CSN);
}
</code></pre>
<p dir="auto">I uploaded the firmware to an Arduino and want to connect it to another Arduino which is programmed with the Serial Gateway sketch.<br />
For discovery of nodes I use the MYSController software on windows, this is working correctly as I can discover my temperature node (which is programmed via arduino with the normal arduino bootloader).</p>
<p dir="auto">But I can't get it to work, am I missing something?<br />
I checked the settings in MyConfig (channel, power etc) but these are the same on the serial gateway sketch and the bootloader.</p>
<p dir="auto">Compiler output for bootloader:</p>
<pre><code>"C:/Program Files (x86)/Arduino/hardware/tools/avr/bin/avr-gcc" -x c -mno-interrupts -funsigned-char -funsigned-bitfields -DF_CPU=16000000L -Os -fno-inline-small-functions -fno-split-wide-types -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -mrelax -Wall -mmcu=atmega328p -c -std=gnu99 -MD -MP -MF "MYSBootloader.d" -MT"MYSBootloader.d" -MT"MYSBootloader.o"  -I../libraries/MySensors MYSB
ootloader.c -o MYSBootloader.o
In file included from MYSBootloader.c:44:0:
MYSBootloader.h:28:2: warning: no semicolon at end of struct or union [enabled by default]
  };
  ^
In file included from MYSBootloaderRF24.h:4:0,
                 from MYSBootloader.h:13,
                 from MYSBootloader.c:44:
MYSBootloaderHW.h:96:13: warning: 'uart_init' defined but not used [-Wunused-function]
 static void uart_init() {
             ^
MYSBootloaderHW.h:126:13: warning: 'put_int' defined but not used [-Wunused-function]
 static void put_int(uint8_t i) {
             ^
"C:/Program Files (x86)/Arduino/hardware/tools/avr/bin/avr-gcc" -nostartfiles -Wl,-s -Wl,-static -Wl,-Map=".map" -Wl,--start-group  -Wl,--end-group -Wl,--gc-sections -mrelax -Wl,-section-start=.text=0x7800 -mmcu=atmega328p   -o MYSBootloader.elf MYSBootloader.o -lm
"C:/Program Files (x86)/Arduino/hardware/tools/avr/bin/avr-objcopy" -O ihex -R .eeprom MYSBootloader.elf MYSBootloader.hex
"C:/Program Files (x86)/Arduino/hardware/tools/avr/bin/avr-size" MYSBootloader.elf
   text    data     bss     dec     hex filename
   2004       2     214    2220     8ac MYSBootloader.elf
</code></pre>
<p dir="auto">Thanks for reading!</p>
<ul>
<li>Ruud</li>
</ul>
]]></description><link>https://forum.mysensors.org/topic/1613/mbsbootloader-with-different-csn-ce-pin-problem</link><generator>RSS for Node</generator><lastBuildDate>Sun, 07 Jun 2026 17:26:38 GMT</lastBuildDate><atom:link href="https://forum.mysensors.org/topic/1613.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 03 Jul 2015 05:28:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to MBSBootloader with different CSN&#x2F;CE Pin problem on Fri, 02 Mar 2018 14:31:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dirkc" aria-label="Profile: dirkc">@<bdi>dirkc</bdi></a> Unfortunately I cannot test the setup right now, but this should work:</p>
<pre><code>...
...
#elif defined(SPI_PINS_CSN9_CE8)
	#define CSN_PORT	PORTB	// port for CSN
	#define CSN_DDR		DDRB	// DDR for CSN
	#define	CSN_PIN		PB1		// Arduino Pin 9 &lt;-&gt; Bit 1 of port B

	#define CE_PORT		PORTB	// port for CE
	#define CE_DDR		DDRB	// DDR for CE
	#define	CE_PIN		PB0		// Arduino Pin  8 &lt;-&gt; Bit 0 of port B
#endif
</code></pre>
<p dir="auto">and</p>
<pre><code>static void initSPI(void) {
	...
        ...
	#elif defined(SPI_PINS_CSN9_CE8)
		// set pin mode: MOSI,SCLK,CE,CSN = OUTPUT, MISO = INPUT (=&gt; all on same port)
		SPI_DDR = _BV(SPI_MOSI) | _BV(SPI_SCLK) | _BV(CE_PIN) | _BV(CSN_PIN) | ~_BV(SPI_MISO);
	#endif
</code></pre>
]]></description><link>https://forum.mysensors.org/post/86475</link><guid isPermaLink="true">https://forum.mysensors.org/post/86475</guid><dc:creator><![CDATA[tekka]]></dc:creator><pubDate>Fri, 02 Mar 2018 14:31:25 GMT</pubDate></item><item><title><![CDATA[Reply to MBSBootloader with different CSN&#x2F;CE Pin problem on Fri, 02 Mar 2018 05:45:47 GMT]]></title><description><![CDATA[<p dir="auto">Thanks, <a class="plugin-mentions-user plugin-mentions-a" href="/user/tekka" aria-label="Profile: tekka">@<bdi>tekka</bdi></a>, but unfortunately  I am still using the wrong code. I tried every combination, but as I am not sure what am doing here, I doubt to make progress.</p>
<p dir="auto">set MOSI,SCLK,CE,CSN to OUTPUT -&gt; <code>SPI_DDR = _BV(SPI_MOSI) | _BV(SPI_SCLK) | _BV(CE_PIN)  | _BV(CSN_PIN)</code><br />
set PB2  to OUTPUT -&gt; <code>| _BV(PB2)</code><br />
set MISO to INPUT -&gt; <code>| ~_BV(SPI_MISO)</code><br />
and set CSN to output -&gt; <code>CSN_DDR = _BV(CSN_PIN);</code></p>
<p dir="auto">The controller still doesn't recognize the node, so I cannot use OTA. But when I flash the sketch (with the CE and CSN pin defined to 8 and 9) with a programmer to an atmega328p with a standard bootloader it works, so my PCB seems ok.</p>
<pre><code>#elif defined(SPI_PINS_CSN9_CE8)
	// set pin mode: MOSI,SCLK,CE,CSN = OUTPUT, MISO = INPUT
	// PB2 is SS pin has to be defined as OUTPUT, else SPI goes to slave mode
	SPI_DDR = _BV(SPI_MOSI) | _BV(SPI_SCLK) | _BV(CE_PIN)  | _BV(CSN_PIN) | _BV(PB2) | ~_BV(SPI_MISO);
	// set CSN = output
	CSN_DDR = _BV(CSN_PIN);
#endif
</code></pre>
<p dir="auto">Looking to other bootloaders was no success, e.g. optiboot.</p>
<p dir="auto">Thanks in advance for any hint or better some sample code.</p>
]]></description><link>https://forum.mysensors.org/post/86437</link><guid isPermaLink="true">https://forum.mysensors.org/post/86437</guid><dc:creator><![CDATA[dirkc]]></dc:creator><pubDate>Fri, 02 Mar 2018 05:45:47 GMT</pubDate></item><item><title><![CDATA[Reply to MBSBootloader with different CSN&#x2F;CE Pin problem on Wed, 28 Feb 2018 22:26:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dirkc" aria-label="Profile: dirkc">@<bdi>dirkc</bdi></a> said in <a href="/post/86400">MBSBootloader with different CSN/CE Pin problem</a>:<br />
I guess you should also set PB2 as output to enable SPI master mode (regardless of your csn assignment)</p>
]]></description><link>https://forum.mysensors.org/post/86410</link><guid isPermaLink="true">https://forum.mysensors.org/post/86410</guid><dc:creator><![CDATA[tekka]]></dc:creator><pubDate>Wed, 28 Feb 2018 22:26:35 GMT</pubDate></item><item><title><![CDATA[Reply to MBSBootloader with different CSN&#x2F;CE Pin problem on Wed, 28 Feb 2018 17:55:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/tekka" aria-label="Profile: tekka">@<bdi>tekka</bdi></a> I also did some changes to assign the SPI pins CSN to pin 9 and CE to pin 8.</p>
<p dir="auto">So the code in the <code>HW.h</code>now looks like this, but I am not sure how to change the <code>initSPI()</code> method:</p>
<pre><code>#elif defined(SPI_PINS_CSN9_CE8)
	#define CSN_PORT	PORTB	// port for CSN
	#define CSN_DDR		DDRB	// DDR for CSN
	#define	CSN_PIN		PB1		// Arduino Pin 9 &lt;-&gt; Bit 1 of port B

	#define CE_PORT		PORTB	// port for CE
	#define CE_DDR		DDRB	// DDR for CE
	#define	CE_PIN		PB0		// Arduino Pin  8 &lt;-&gt; Bit 0 of port B
#endif

</code></pre>
<pre><code>static void initSPI(void) {
	// Initialize the SPI pins: SCK, MOSI, CE, CSN as outputs, MISO as input
	#if defined(SPI_PINS_CE9_CSN10)
		// CSN_PIN (=PB2) is SS pin and set as output
		SPI_DDR = _BV(SPI_MOSI) | _BV(SPI_SCLK) | _BV(CE_PIN) | _BV(CSN_PIN);
	#elif defined(SPI_PINS_CSN7_CE8)
		// PB2 is SS pin has to be defined as OUTPUT, else SPI goes to slave mode
		SPI_DDR = _BV(SPI_MOSI) | _BV(SPI_SCLK) | _BV(CE_PIN) | _BV(PB2);	
		CSN_DDR = _BV(CSN_PIN);
	#elif defined(SPI_PINS_CSN9_CE8)
		// set pin mode: MOSI,SCLK,CE,CSN = OUTPUT, MISO = INPUT
		SPI_DDR = _BV(SPI_MOSI) | _BV(SPI_SCLK) | _BV(CE_PIN) | _BV(CSN_PIN) | ~_BV(SPI_MISO);
		// set CSN = output
		CSN_DDR = _BV(CSN_PIN);
	#endif
</code></pre>
<p dir="auto">Is there any further code I have to change?</p>
<p dir="auto">Thanks in advance for any hint, I am not used to code on that bit level and AVR macros.</p>
]]></description><link>https://forum.mysensors.org/post/86400</link><guid isPermaLink="true">https://forum.mysensors.org/post/86400</guid><dc:creator><![CDATA[dirkc]]></dc:creator><pubDate>Wed, 28 Feb 2018 17:55:39 GMT</pubDate></item><item><title><![CDATA[Reply to MBSBootloader with different CSN&#x2F;CE Pin problem on Sat, 14 Nov 2015 03:39:36 GMT]]></title><description><![CDATA[<p dir="auto">For some reason, <a class="plugin-mentions-user plugin-mentions-a" href="/user/ruud-harmsen" aria-label="Profile: Ruud-Harmsen">@<bdi>Ruud-Harmsen</bdi></a>'s bootloader didn't work for me.</p>
<p dir="auto">My copy's attached.  Same pins and rf24 config; but also added five flashes to an LED connected to pin D9, so you can tell when it's in a reboot loop.</p>
<p dir="auto">Source here: <a href="https://github.com/peterdey/MySensors-Arduino/tree/master/MYSBootloader" rel="nofollow ugc">https://github.com/peterdey/MySensors-Arduino/tree/master/MYSBootloader</a></p>
<p dir="auto"><a href="/uploads/files/1447472343751-mysbootloader.hex">MYSBootloader.hex</a></p>
]]></description><link>https://forum.mysensors.org/post/24520</link><guid isPermaLink="true">https://forum.mysensors.org/post/24520</guid><dc:creator><![CDATA[pdey]]></dc:creator><pubDate>Sat, 14 Nov 2015 03:39:36 GMT</pubDate></item><item><title><![CDATA[Reply to MBSBootloader with different CSN&#x2F;CE Pin problem on Mon, 06 Jul 2015 20:33:58 GMT]]></title><description><![CDATA[<p dir="auto">Thanks <a class="plugin-mentions-user plugin-mentions-a" href="/user/tekka" aria-label="Profile: tekka">@<bdi>tekka</bdi></a>, that worked!</p>
<p dir="auto">I attached the bootloader for other interested people.</p>
<p dir="auto">Settings:<br />
CSN pin: 7<br />
CE pin: 8</p>
<pre><code>#define RF24_CHANNEL	   90             //RF channel for the sensor net, 0-127
#define RF24_DATARATE 	   RF24_250KBPS   //RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps
#define RF24_PA_LEVEL 	   RF24_PA_MAX    //Sensor PA Level == RF24_PA_MIN=-18dBm, RF24_PA_LOW=-12dBm, RF24_PA_HIGH=-6dBM, and RF24_PA_MAX=0dBm
#define RF24_PA_LEVEL_GW   RF24_PA_LOW  //Gateway PA Level, defaults to Sensor net PA Level.  Tune here if using an amplified nRF2401+ in your gateway.
#define BASE_RADIO_ID 	   ((uint64_t)0xA8A8E1FC00LL) // This is also act as base value for sensor nodeId addresses. Change this (or channel) if you have more than one sensor network.
</code></pre>
<p dir="auto"><a href="/uploads/files/1436214671257-mysbootloader.hex">MYSBootloader.hex</a></p>
]]></description><link>https://forum.mysensors.org/post/16662</link><guid isPermaLink="true">https://forum.mysensors.org/post/16662</guid><dc:creator><![CDATA[Ruud Harmsen]]></dc:creator><pubDate>Mon, 06 Jul 2015 20:33:58 GMT</pubDate></item><item><title><![CDATA[Reply to MBSBootloader with different CSN&#x2F;CE Pin problem on Sun, 05 Jul 2015 12:11:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ruud-harmsen" aria-label="Profile: Ruud-Harmsen">@<bdi>Ruud-Harmsen</bdi></a> you use the data direction register (DDRD) instead of PORTD to control CSN.</p>
]]></description><link>https://forum.mysensors.org/post/16555</link><guid isPermaLink="true">https://forum.mysensors.org/post/16555</guid><dc:creator><![CDATA[tekka]]></dc:creator><pubDate>Sun, 05 Jul 2015 12:11:13 GMT</pubDate></item></channel></rss>