SOLVED: Need help getting some basic things to work

User avatar
denanden
Posts: 10
Joined: Mon Aug 29, 2016 3:43 pm

SOLVED: Need help getting some basic things to work

Postby denanden » Mon Aug 29, 2016 8:25 pm

Hi everybody.

I'm completely new to Maple Mini and still new to Arduino, so please be patient with me ;)

First of all, I want to use the hardware SPI ports but if I reference HardwareSPI in my code it doesn't compile. Am I missing an include?
I found some other class (SPIClass) that compiles and works but I prefer a hardware accelerated implementation.

The following things also seem to be missing:
- BOARD_LED_PIN
- BOARD_BUTTON_PIN
- toggleLED()

So again, am I missing some includes? Is my entire setup "sick"?
Last edited by denanden on Sat Sep 03, 2016 10:44 pm, edited 1 time in total.

edogaldo
Posts: 167
Joined: Fri Jun 03, 2016 8:19 am

Re: Need help getting some basic things to work

Postby edogaldo » Mon Aug 29, 2016 9:10 pm

denanden wrote:Hi everybody.

I'm completely new to Maple Mini and still new to Arduino, so please be patient with me ;)

First of all, I want to use the hardware SPI ports but if I reference HardwareSPI in my code it doesn't compile. Am I missing an include?
I found some other class (SPIClass) that compiles and works but I prefer a hardware accelerated implementation.

The following things also seem to be missing:
- BOARD_LED_PIN
- BOARD_BUTTON_PIN
- toggleLED()

So again, am I missing some includes? Is my entire setup "sick"?

Did you try the spi example in the spi library? This could be a good starting point.

User avatar
RogerClark
Posts: 5466
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Need help getting some basic things to work

Postby RogerClark » Mon Aug 29, 2016 11:44 pm

The definitions for BOARD_LED_PIN were removed in an effort to make the core more generic, but I suppose we could add them back in

Code: Select all

#define BOARD_LED_PIN PB1
#define BOARD_BUTTON_PIN PB8


toggleLed is not a standard Arduino function so has been removed and will not be reinstated as the code to toggle the LED is trivial

Code: Select all

digitWrite(BOARD_LED_PIN,!digitalRead(BOARD_LED_PIN));



SPI works in the same way it does on other Arduino boards, just include <SPI.h>

and an instance of SPIClass called SPI gets instantiated for you.

User avatar
denanden
Posts: 10
Joined: Mon Aug 29, 2016 3:43 pm

Re: Need help getting some basic things to work

Postby denanden » Tue Aug 30, 2016 5:45 pm

Thanks for your answers edogaldo and RogerClark :)

Still, I'm confused: Is the SPIClass using hardware SPI?

User avatar
RogerClark
Posts: 5466
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Need help getting some basic things to work

Postby RogerClark » Tue Aug 30, 2016 8:41 pm

We only have Hardware SPI.

Its just the same as using any other Arduino.

We even have DMA SPI transfers if you want to use them ( albeit blocking rather than non-blocking)

Note SPI speed can be as fast as 36 M bps, which exceeds the SPI spec, but seems to work with most peripherals

User avatar
denanden
Posts: 10
Joined: Mon Aug 29, 2016 3:43 pm

Re: Need help getting some basic things to work

Postby denanden » Wed Aug 31, 2016 8:01 pm

Thanks :)

Now my next problem: I'm trying to get my SD card module to work with an example read/write sketch but it doesn't want to.
I have the Catalax MicroSD Card Adapter which has a chip with LVC125A written on it.
It works fine with my Nano, but I don't get past the SD.open() on my Maple Mini (clone).
I changed the CS pin to 10, and I also tried connecting CS to pin 7 (SS on SPI1) but with the same result.
The board LED sort of flashes medium speed and doesn't quite turn off in between each blink.

I really need the SD to work... so any help will be appreciated.

EDIT: The CardInfo example sketch works and correctly reports the files on the cards that I tried it with.

User avatar
Pito
Posts: 611
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Need help getting some basic things to work

Postby Pito » Wed Aug 31, 2016 9:12 pm

The LV125 is a level shifter (Nano is 5V afaik, Sdcard is 3.3V).
Maple Mini is 3.3V, so you do not need the level shifter..
For Maple Mini and BluePill you have to connect the Sdcard directly pin to pin..

User avatar
denanden
Posts: 10
Joined: Mon Aug 29, 2016 3:43 pm

Re: Need help getting some basic things to work

Postby denanden » Sun Sep 04, 2016 1:52 am

Pito wrote:For Maple Mini and BluePill you have to connect the Sdcard directly pin to pin..

Which pin to which pin? I have Vcc on the SD card adapter connected to pin Vin on the Maple Mini (which is +5V when powered through USB).
Everything is "pin to pin" with CS being the only exception (pin 10).

I found out that it hangs on the call to malloc() in File.cpp :?
Is this a known problem?
Is there a workaround?

-------------------------
PROBLEM SOLVED: I'm using Visual Studio with the VisualMicro plugin and It seems that this tool has a problem with malloc() and free(). When I built the sketch with Arduino 1.6.11 the example worked alright.

To make the SD library work for me with Visual Micro, I made the following changes:

In SD.h:

Code: Select all

class File : public Stream {
 private:
  char _name[13]; // our name
  SdFile _file;  // underlying file  <---- THIS LINE

public:
  File(SdFile& f, const char *name);     // wraps an underlying SdFile <---- AND THIS LINE
  File(void);      // 'empty' constructor

Then in File.cpp changed the constructors to:

Code: Select all

File::File(SdFile& f, const char *n)
{
    _file = f;
    strncpy(_name, n, 12);
    _name[12] = 0;
}

File::File(void) : _file() {
  _name[0] = 0;
  //Serial.print("Created empty file object");
}
then removed the call to free() and the rest is trivial.

Maybe someone knows why the original constructor created a copy of the argument SdFile? And why it used memcpy() rather than simple assignment? Sorry, I don't really have much experience with C++...


Return to “Maple mini”

Who is online

Users browsing this forum: No registered users and 1 guest