<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: HardwareSPI understanding</title>
		<link>http://forums.leaflabs.com/topic.php?id=10411</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:08:02 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=10411" rel="self" type="application/rss+xml" />

		<item>
			<title>higwoshy on "HardwareSPI understanding"</title>
			<link>http://forums.leaflabs.com/topic.php?id=10411#post-23234</link>
			<pubDate>Sat, 23 Mar 2013 13:25:54 +0000</pubDate>
			<dc:creator>higwoshy</dc:creator>
			<guid isPermaLink="false">23234@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I seem to remember I tried something similar and ran into the problem of HardwareSPI not having a default initialiser. i.e. it needs &#60;code&#62;HardwareSPI blob(2);&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;Which is fine in main etc, but inside a class definition it won't allow it to be 'initialised here'. So if you have &#60;code&#62;HardwareSPI blob&#60;/code&#62; it complains about blob not being initialised, but if you try to initialise it &#60;code&#62;...blob(2)&#60;/code&#62;, the compiler complains about 'you can't do that here'. (I'm C++ rusty, but I think it's because the class definition is only a definition so you can't init something that doesn't exist). &#60;/p&#62;
&#60;p&#62;I got round the problem by just having it global, and maybe that's why it was done that way - having several classes that operate on a hardware port may leave it in an undefined state??? You probably know more about this than I do, I'm not 100% c++ orientated.&#60;/p&#62;
&#60;p&#62;If you just have one logger file opened, then I see no problem with making it global and allowing classes to use it - so setup() would setup the logger files(s), then pass this file handle on initialising of the class - if you see what I mean. Either leave it open all the time and periodically flush it, or open/write/close the file each time. &#60;/p&#62;
&#60;p&#62;When you work out a better solution, feel free to share it.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>raymadigan on "HardwareSPI understanding"</title>
			<link>http://forums.leaflabs.com/topic.php?id=10411#post-23043</link>
			<pubDate>Fri, 22 Mar 2013 18:01:49 +0000</pubDate>
			<dc:creator>raymadigan</dc:creator>
			<guid isPermaLink="false">23043@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;The problem is I don''t know how to create a global variable that can be seen by the Libraries.  I don''t think I have access to main, or don''t know how to get it.&#60;/p&#62;
&#60;p&#62;I have a temporary work around where I create a global SdFile and have any class that needs to write to the logger extern this variable.  Then I can pass the logger from class instance to class instance.  As long as everyone who writes to the logger is well behaved then it will work until I figure out the real solution.&#60;/p&#62;
&#60;p&#62;I haven''t tried it with multiple devices yet, I will do that test tonight.&#60;/p&#62;
&#60;p&#62;Thanks for your help.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>higwoshy on "HardwareSPI understanding"</title>
			<link>http://forums.leaflabs.com/topic.php?id=10411#post-23042</link>
			<pubDate>Fri, 22 Mar 2013 16:41:01 +0000</pubDate>
			<dc:creator>higwoshy</dc:creator>
			<guid isPermaLink="false">23042@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Personally, I'd use a global hardwareSPI  as there are only 2 SPI ports available and probably only one SD card. Keep it simple. The Maple isn't a multi-tasking system, so unless your writing to SPI from a interrupt (probably not a good idea) then each class has exclusive use of the SD card until it finishes. Your classes would just need to keep a file handle open for each logger file, allowing each class to write to it's own file (or one file if you keep the file handle the same between all classes). &#60;/p&#62;
&#60;p&#62;That's one option, I'm sure there a lots of others.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>raymadigan on "HardwareSPI understanding"</title>
			<link>http://forums.leaflabs.com/topic.php?id=10411#post-23041</link>
			<pubDate>Fri, 22 Mar 2013 15:39:16 +0000</pubDate>
			<dc:creator>raymadigan</dc:creator>
			<guid isPermaLink="false">23041@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I have a maple mini application I have been working on for the past year.  it works well as it is.  I just decided that it would be good to add the code to make the sd card reader that I have on the board work.  &#60;/p&#62;
&#60;p&#62;The application has migrated to a class oriented project with 90% of the software in a set of classes.  I implement this through libraries.  The basic structure is&#60;/p&#62;
&#60;p&#62;Device[Can be several]&#60;br /&#62;
  Manager[one per Device]&#60;br /&#62;
  Sampler[one per device]&#60;br /&#62;
  Duty[one per device]&#60;/p&#62;
&#60;p&#62;I have started implementing the sd card as a Logger class with the Device creating the instance.  The logger has an instance of the HardwareSPI class, with two devices there are two HardwareSPI instances.  This works and each Device can write to the card successfully.  Each device completes its writing task before it gives up control.&#60;/p&#62;
&#60;p&#62;The problem is that I also need the Manager and the Sampler to be able to write to the sd card.  This brings up all kinds of memory allocation issues if I just pass the logger instance to the Sampler or Manager.  &#60;/p&#62;
&#60;p&#62;I am heading to the model where each class that needs to write to the sd card inherits from a logger base class.  The issue is there will be potentially many instances of the HardwareSPI class instantiated and don''t understand it well enough to know if this causes an issue.&#60;/p&#62;
&#60;p&#62;I can post as much code as is needed, I didn''t think it would help.&#60;/p&#62;
&#60;p&#62;Any advise would be appreciated.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
