BlockoS / arduino-dataflash

Support for Atmel Dataflash for the Arduino
http://blockos.github.com/arduino-dataflash
23 stars 14 forks source link

Read status register command not working with Mega2650 #22

Open perigalacticon opened 7 years ago

perigalacticon commented 7 years ago

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.

BlockoS commented 7 years ago

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

perigalacticon commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

`

BlockoS commented 7 years ago

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...

perigalacticon commented 7 years ago

Should this library work for the ARM SAMD11?

BlockoS commented 7 years ago

Yes if the Arduino SDK was ported.

perigalacticon commented 7 years ago

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 notifications@github.com 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.

BlockoS commented 7 years ago

Yes I can do it :)

perigalacticon commented 7 years ago

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 notifications@github.com 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.

BlockoS commented 7 years ago

Ok. I'll try to finish it for tomorrow

BlockoS commented 7 years ago

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.

perigalacticon commented 7 years ago

Thanks!

I'll give it a try tonight.


From: MooZ notifications@github.com 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.