arduino-dataflash icon indicating copy to clipboard operation
arduino-dataflash copied to clipboard

Read status register command not working with Mega2650

Open perigalacticon opened this issue 6 years ago • 13 comments

I've used the library with a AT45DB011D and an Uno successfully, but when using with a Mega2650 I get nothing returned from the read status register command. I found I have to use a CS pin other than the Mega2650 SPI SS pin which is pin 53.

perigalacticon avatar Sep 14 '17 21:09 perigalacticon

Weird... Does it have a 5V/3.3V switch? If so, make sure it's on 3.3V.

BlockoS avatar Sep 17 '17 14:09 BlockoS

No it doesn't. I'd like to use this lib on a SAMD11 board now, but it gives the compiler error:

`C:\Program Files (x86)\Arduino\libraries\DataFlash\DataFlash.cpp: In member function 'void DataFlash::setup(int8_t, int8_t, int8_t)':

C:\Program Files (x86)\Arduino\libraries\DataFlash\DataFlash.cpp:152:15: error: 'SPSR' was not declared in this scope

 m_SPSR = (SPSR & SPI_2XCLOCK_MASK);

           ^`

Should this lib work with the SAMD11? If not can it be modified to do so? If you want I make this as a different issue.

perigalacticon avatar Sep 18 '17 18:09 perigalacticon

I am using the Beta core from MattairTech:

https://github.com/mattairtech/ArduinoCore-samd

https://www.mattairtech.com/software/arduino/beta/package_MattairTech_index.json

perigalacticon avatar Sep 18 '17 18:09 perigalacticon

I think the problem may be with the definition of SPI_2XCLOCK_MASK, I found it in Arduino file SPI.h: https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/libraries/SPI/src/SPI.h

#define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR

perigalacticon avatar Sep 18 '17 19:09 perigalacticon

SPSR, SPCR are AVR registers.. They doesn't seem to be used. You may remove m_SPSR and m_SPCR.

I also realized that the SPI interface has changed...

BlockoS avatar Sep 18 '17 19:09 BlockoS

Should this library work for the ARM SAMD11?

perigalacticon avatar Sep 18 '17 19:09 perigalacticon

Yes if the Arduino SDK was ported.

BlockoS avatar Sep 18 '17 19:09 BlockoS

MooZ,

I have been working with the AT45DB011D which you helped me adapt the library to use. I found that the Write Protect pin does not protect the chip unless the Sector Protection Register has been enabled. However, I don't see commands for that within your library. Are these commands available? If not, can you add them?

Sincerely,

Stephen


From: MooZ [email protected] Sent: Monday, September 18, 2017 3:23 PM To: BlockoS/arduino-dataflash Cc: perigalacticon; Author Subject: Re: [BlockoS/arduino-dataflash] Read status register command not working with Mega2650 (#22)

Yes if the Arduino SDK was ported.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/BlockoS/arduino-dataflash/issues/22#issuecomment-330329226, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AETnkmdudQrWdqADjGv5ouRPfmG4bqFMks5sjsMcgaJpZM4PYM-8.

perigalacticon avatar Oct 12 '17 02:10 perigalacticon

Yes I can do it :)

BlockoS avatar Oct 16 '17 06:10 BlockoS

Hey Mooz, is there any chance you can do this soon, as I'm building a project for halloween?

I'm using the AT45DB321D


From: MooZ [email protected] Sent: Monday, October 16, 2017 2:57 AM To: BlockoS/arduino-dataflash Cc: perigalacticon; Author Subject: Re: [BlockoS/arduino-dataflash] Read status register command not working with Mega2650 (#22)

Yes I can do it :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/BlockoS/arduino-dataflash/issues/22#issuecomment-336796725, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AETnkgysU7jrwN01BelMyjByKrN5haWWks5ssv5rgaJpZM4PYM-8.

perigalacticon avatar Oct 22 '17 05:10 perigalacticon

Ok. I'll try to finish it for tomorrow

BlockoS avatar Oct 22 '17 08:10 BlockoS

Done! Well more or less (not happy with the API and comments are missing). You can find an example in examples/sectorProtection/sectorProtection.pde Anyway here's a short example.

  DataFlash::SectorProtectionStatus protection;
  uint8_t sectorCount;

  // Protect only sector 2.
  protection.set(2, true);
 
  // Enable sector protection.
  dataflash.enableSectorProtection();
  // Set sector protection register.
  dataflash.programSectorProtectionRegister(protection);

  // Sector 2 is now protected.

  // Sectors are not protected anymore.
  dataflash.disableSectorProtection();

I also need to add a method to compute the first and last page index of a given sector.

BlockoS avatar Oct 23 '17 21:10 BlockoS

Thanks!

I'll give it a try tonight.


From: MooZ [email protected] Sent: Monday, October 23, 2017 5:30 PM To: BlockoS/arduino-dataflash Cc: perigalacticon; Author Subject: Re: [BlockoS/arduino-dataflash] Read status register command not working with Mega2650 (#22)

Done! Well more or less (not happy with the API and comments are missing). You can find an example in examples/sectorProtection/sectorProtection.pde Anyway here's a short example.

DataFlash::SectorProtectionStatus protection; uint8_t sectorCount;

// Protect only sector 2. protection.set(2, true);

// Enable sector protection. dataflash.enableSectorProtection(); // Set sector protection register. dataflash.programSectorProtectionRegister(protection);

// Sector 2 is now protected.

// Sectors are not protected anymore. dataflash.disableSectorProtection();

I also need to add a method to compute the first and last page index of a given sector.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/BlockoS/arduino-dataflash/issues/22#issuecomment-338802749, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AETnki7ihyLAYYbR8DTFxZNlRBX98Q0zks5svQV5gaJpZM4PYM-8.

perigalacticon avatar Oct 23 '17 23:10 perigalacticon