Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read status register command not working with Mega2650 #22

Open
perigalacticon opened this issue Sep 14, 2017 · 13 comments
Open

Read status register command not working with Mega2650 #22

perigalacticon opened this issue Sep 14, 2017 · 13 comments

Comments

@perigalacticon
Copy link

perigalacticon commented Sep 14, 2017

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
Copy link
Owner

BlockoS commented Sep 17, 2017

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

@perigalacticon
Copy link
Author

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
Copy link
Author

@perigalacticon
Copy link
Author

perigalacticon commented Sep 18, 2017

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
Copy link
Owner

BlockoS commented Sep 18, 2017

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
Copy link
Author

Should this library work for the ARM SAMD11?

@BlockoS
Copy link
Owner

BlockoS commented Sep 18, 2017

Yes if the Arduino SDK was ported.

@perigalacticon
Copy link
Author

perigalacticon commented Oct 12, 2017 via email

@BlockoS
Copy link
Owner

BlockoS commented Oct 16, 2017

Yes I can do it :)

@perigalacticon
Copy link
Author

perigalacticon commented Oct 22, 2017 via email

@BlockoS
Copy link
Owner

BlockoS commented Oct 22, 2017

Ok. I'll try to finish it for tomorrow

@BlockoS
Copy link
Owner

BlockoS commented Oct 23, 2017

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
Copy link
Author

perigalacticon commented Oct 23, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants