Netduino + Ethernet Shield: How to write to SD card? - netduino

I have tried several example programs to write data to the SD card mounted on the Ethernet shield, but none worked. The SD card size is 4 GB and formatted as FAT32.
The Ethernet shield is the following:
(Bought on Amazon - Arduino Ethernet Shield)
And this is example code that doesn't work when creating a Netduino application (not Netduino Plus application) (thefirst line throws an exception):
public static void Main()
{
StorageDevice.MountSD("SD1", SPI_Devices.SPI1, Pins.GPIO_PIN_D10);
string[] directories = System.IO.Directory.GetDirectories(#"\");
Debug.Print("directory count: " + directories.Length.ToString());
for (int i = 0; i < directories.Length; i++)
{
Debug.Print("directory: " + directories[i]);
}
string[] files = System.IO.Directory.GetFiles(#"\SD1");
Debug.Print("file count: " + files.Length.ToString());
for (int i = 0; i < files.Length; i++)
{
Debug.Print("filename: " + files[i]);
FileStream fs = new FileStream(files[i], FileMode.Open, FileAccess.Read, FileShare.None, 512);
StreamReader sr = new StreamReader(fs);
Debug.Print("contents: " + sr.ReadToEnd());
}
}
Is there a example working program?
Solution:
Thanks to Chris and James, I managed to write to the SD card and read from it. After putting everything together, I wrote an article, in case anyone else faces the same issues.

The latest revision of the Arduino Ethernet Shield uses the "ICSP" header (3x2, 6-pin header on right side of board) to communicate. The input/output data going to your SD card is going over those pins.
We've included these same headers on the Netduino for compatibility; to use this shield, you'll want to solder the appropriate header onto your Netduino. Then you should be good to go!
BTW, Netduino Plus has integrated MicroSD and fast Ethernet networking...which may be an easy solution as well. http://www.netduino.com/netduinoplus/
Chris (Secret Labs LLC)

I found a reference on this forum page http://forums.netduino.com
"you'll currently need to put a jumper wire between D10 and D4 to get
the SD card to work--although that will not be necessary with the
production v4.1.1 firwmare (which will let you specify the SD card's
chip select line)."
Which makes me think that you need to use D4 instead of D10 for the SD Card. I found some other references on the same page that mentioned D10 is the SS pin for the Ethernet. The Firmware available on their download page is currently only 4.1.0 so you will probably need the jumper. I can't test this but the forum link should be a good starting point.

Related

STM32F103 SPI different pins does not work

I am currently working on a project with LoRaWAN technology using STM32F103C8T6 microcontroller. For LoRa I am using SPI in Full-Duplex Master mode (spi1 specifically) and in CubeIDE when you activate SPI1, automatically pins PA5, PA6 and PA7 are activated (ver1):
However, PCB is designed and printed and those pins are unfortunately busy. Because, before it was planned to use other SPI1 pins (PB3, PB4, PB5) (ver2):
So, when I use ver1, all is good, LoRa connects to server and sends data without a problem. However, when I use ver2, it does not work at all. I debugged to find where is problem and found out that, SPI read fails (when version of LoRa is read, it returns 0). Thus, ASSERT fires and code is stuck in infinite loop. I could not find any reference of difference of SPI pins in the internet.
Can anyone explain the difference of these pins? And is it possible to use ver2? Thanks beforehand.
P.S. I am using HAL Library + LMIC library (for LoRa) and the configuration of SPI are the same for both ver1 and ver2. Here is code of configuration, if needed:
void MX_SPI1_Init(void)
{
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 10;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
}
P.S.S: I also gave this question in electronics stackexchange, but there was no answer there, so I decided to share the question here too.
After lots of tries, I found out that, remapped SPI1 does not work together with I2C1, because of I2C1-SMBA pin overlap with SP1 MOSI pin (PB5), even if you are not using SMBA. You can find about that here: STM32F103x8 errata chapter 2.8.7
So, I guess, I will use I2C2 for avoiding collision. The only change I should make on PCB would be redirecting I2C1 pins to I2C2 (2 pins), which is way better than redirecting SPI1 pins (3 pins) and other elements occupying ver1 (also 3) pins.

Movesense CustomGATT and ECG or Accelerometer

There have been a few posts on this issue without any solutions announced.
Wanting to access internal movesense sensor data (ECG, Acc…) but without using the Android or iOS platforms ( as suggested by a movesense presentation https://www.movesense.com/wp-content/uploads/2018/11/2018-11-06-Using-Movesense-CustomGATTService.pdf ), I have failed to do so for at least 1 week.
I can successfully create my own GATT characteristics and subscribe to them from outside the movesense device. This is easily done by augmenting the samples/custom_gattsvc_app with a few lines :
Definition :
const uint16_t myCharUUID16 = 0x2A58; // this new characteristic will appear in the service as the third one in the sample
In CustomGATTSvcClient::configGattSvc() :
WB_RES::GattProperty myCharProp = WB_RES::GattProperty::INDICATE;
myChar.props = wb::MakeArray<WB_RES::GattProperty>( &myCharProp, 1);
myChar.uuid = wb::MakeArray<uint8_t>( reinterpret_cast<const uint8_t*>(&myCharUUID16), 2);
customGattSvc.chars = wb::MakeArray<WB_RES::GattChar>(characteristics, 3); // 3 here since there are 3 characteristics now
Accessing
You can now see and subscribe with a BTLE client (bluetility…) to the new service even if it does not do anything for now.
The problems start here for me :
In CustomGATTSvcClient::onGetResult() I try to force a subscription to ECG or Acc since onGetResult() is called by CustomGATTSvcClient::onPostResult() once all the BT services are created :
int32_t sampleRate = 10;
asyncSubscribe(WB_RES::LOCAL::MEAS_ACC_SAMPLERATE(),AsyncRequestOptions::Empty, sampleRate);
I do not implement onSubscribeResult()
In onNotify() you should be able to intercept the call from the whiteboard with the new data every 1/10 second by
switch (resourceId.getConstId()) {
case WB_RES::LOCAL::MEAS_ACC_SAMPLERATE::ID:
{
// To see a blinking LED on each new Acc data
asyncPut(WB_RES::LOCAL::COMPONENT_LED(),AsyncRequestOptions::Empty, myFlippingBool);
myFlippingBool = ! myFlippingBool;
}
What I have observed :
A. When I asyncSubscribe() the ECG or Acc, the sample’s WB_RES::LOCAL::MEAS_TEMP::LID is no longer called and no updates are dispatched to a BT client even after a successful subscription to the 0x2A1C characteristic. This means that all Notifications are disabled by a resource conflict ?
B. When subscribing ( as before ) or even by :
wb::Result result = getResource("Meas/Acc/10", mMyAccResourceId);
result = asyncSubscribe(mMyAccResourceId);
The onNotify() method is never called as the LED does not blink ( even directly after onNotify() implementation without the switch / case )
There is a lack of documentation on CustomGatt and it seems it blocks many people in integrating the sensor on other platforms ( Raspberry Pi or generic processors running a BT stack ).
I have tried before to access the movesense platform with direct AT commands from a rudimentary microcontroller and a BT module without success (Movesense direct access to GATT endpoints ), so now I’m turning to a Raspberry solution + Qt without success.
Thank you for any example or answers to this question !
At least 10 Hz is not supported. What happens with Meas\Acc\13 ?

Bluetooth and MSP430G2

I took MSP430G2 and Bluetooth (JY-MCU Bluetooth Wireless Serial Port Module). Today I decided to try them and tied them in the following manner as explained http://galfama.blogspot.com/2013/02/control-de-leds-del-msp430-launchpad.html . All downloaded super and application Android BlueTerm, let the application run, and MSP-it got the following program:
char valor=0;
void setup()
{
Serial.begin(9600);
}
void loop() //Bucle infinito
{
if (Serial.available())//Si hay una caracter en el buffer serial
{
valor = Serial.read();// Se lee el valor numérico en el puerto serie.
Serial.print(valor);
}
}
Connect to the bluetooth and when I start to write nothing happens. Dropped a Putty, but there nothing, nothing appears. However, when the two exchanged cable (TXD) and (RXD). Putty and run the program and when I write something in Putty appear symbols. If anyone can help would be great.
I fixed your problem. And here's what he was. My numbers chip is M430G2553, I compiled and uploaded for M430G2452. And hence the problem.
For writing the program code used Energia. Comfortable me because it is one written for Arduino. Will definitely go then C, but for starters I think it's great.
Here is a picture of what chip concerns

atmel sensor using printf

I have an atmel UC3-L0 and compass sensor. Now I install AtmelStudio and download some demo code into the board. But I have no idea where the function printf in demo code will appear the data. How should I do to get the data?
The printf function outputs to stdout.
Usually on a "naked" processor with no operating system you need to define how a character is sent or received from a physical interface (usually an USART, console port, USB port, 4-port LCD interface, etc.). So typically you may want to use the USART port of your processor board to connect to a PC running Hyperterm, PuTTY or similar using a serial cable.
In essence you will need to
create FILE streams using the fdev_setup_stream() macro and
provide pointers to functions get() and put() that tell the printf() function how exactly to read and write from/to that stream (e.g. read/write to a USART, an LCD display, etc.).
you may have libraries - depending on your hardware - that already contain such functions (plus the correct port initialisation functions), like e.g. uart.c/.h, lcd.c/.h, etc.
In the documentation of stdio.h (e.g. here) look for the following:
printf(), fdev_setup_stream()
If you have downloaded Atmel Studio you may look into the stdiodemo.c code for further insight.
In order to use printf in ATMEL studio you should check the following things:
Add and Apply the Standard serial I/O module from Project->ASF Wizard.
Also add the USART module from the ASF Wizard.
Include the following code snippet before the main function.
static struct usart_module usart_instance;
static void configure_console(void)
{
struct usart_config usart_conf;
usart_get_config_defaults(&usart_conf);
usart_conf.mux_setting = EDBG_CDC_SERCOM_MUX_SETTING;
usart_conf.pinmux_pad0 = EDBG_CDC_SERCOM_PINMUX_PAD0;
usart_conf.pinmux_pad1 = EDBG_CDC_SERCOM_PINMUX_PAD1;
usart_conf.pinmux_pad2 = EDBG_CDC_SERCOM_PINMUX_PAD2;
usart_conf.pinmux_pad3 = EDBG_CDC_SERCOM_PINMUX_PAD3;
usart_conf.baudrate = 115200;
stdio_serial_init(&usart_instance, EDBG_CDC_MODULE, &usart_conf);
usart_enable(&usart_instance);
}
Make Sure you call the configure_console after system_init() from the main function.
Now go to tools->extension manager. Add the terminal window extension.
Build and Run your program and open the terminal window from view-> terminal window. put the correct com port to which your device is running on and set the baud to 115200 and hit connect on the terminal window.
You should see the printf statements now. (Float doesn't get printed in Atmel studio)
I was recently puzzling over this myself. I has installed Atmel Studio 7.0 and was using the SAMD21 Dev Board via an example project in which a call to printf was made.
In the sample code I saw that there was a configuration section:
/*!
* \brief Initialize USART to communicate with on board EDBG - SERCOM
* with the following settings.
* - 8-bit asynchronous USART
* - No parity
* - One stop bit
* - 115200 baud
*/
static void configure_usart(void)
{
struct usart_config config_usart;
// Get the default USART configuration
usart_get_config_defaults(&config_usart);
// Configure the baudrate
config_usart.baudrate = 115200;
// Configure the pin multiplexing for USART
config_usart.mux_setting = EDBG_CDC_SERCOM_MUX_SETTING;
config_usart.pinmux_pad0 = EDBG_CDC_SERCOM_PINMUX_PAD0;
config_usart.pinmux_pad1 = EDBG_CDC_SERCOM_PINMUX_PAD1;
config_usart.pinmux_pad2 = EDBG_CDC_SERCOM_PINMUX_PAD2;
config_usart.pinmux_pad3 = EDBG_CDC_SERCOM_PINMUX_PAD3;
// route the printf output to the USART
stdio_serial_init(&usart_instance, EDBG_CDC_MODULE, &config_usart);
// enable USART
usart_enable(&usart_instance);
}
In windows device manager I saw that there was an "Atmel Corp. EDBG USB Port (COM3)" listed under "Ports". However, the one of the "Properties" of this port was listed as 9600 Bits per second. I changed this from 9600 to 115200 to be consistent with the config section above.
Finally, I ran PuTTY.exe and set the Connection-->Serial setting to COM3 and 115200 baud. Then I went to Session, then clicked the Serial Connection Type, then clicked the Open button. And, BAM, there's my printf output via PuTTY.

Using Port DD as GPIO on MCF5282

I’ve got a MCF5282 that I’m trying to use PDD4 as a GPIO on. In my setup code, I’ve got:
MCF5282_GPIO_DDRDD = 0x10; /* cs on dd4. */
MCF5282_GPIO_PORTDD = 0x10; /* active-low. */
And in my main loop, I’ve got:
MCF5282_GPIO_PORTDD = (mainloop_cnt & 0x10);
Which should give me a nice square wave on the oscilloscope, but the port doesn’t seem to be doing as I say. Am I missing some setup steps? I can’t find anything in the 5282 manual about a “Port DD pin-assignment register” to repurpose it from its “primary” role as DDATA.
Edit 2011-03-01: We never figured this out, we just used a different pin for GPIO.
You probably need to clear PSTEN in the Chip Configuration Register to disable DDATA, see page 27-4 of the MCF5282 and MCF5216 ColdFire Microcontroller User’s Manual