Loading...
  Show Posts
Pages: [1] 2
1  Using Arduino / Storage / Re: Dataflash AT45DB161D and Arduino Leonardo on: November 13, 2012, 11:32:25 am
Okay so i finally got the AT45DB161D to work with the leonardo. I used another library i found online http://blockos.github.com/arduino-dataflash/ maybe this can be helpful for someone else. The pageTest example in the library should work with little work, but i found it to be more geared towards uno and duemilanove. Below is a little sketch i wrote to test the Lenonardo. you can also download it from here http://code.google.com/p/osyrisos/downloads/list

Code:
// DATAFLASH LEONARDO TEST.
//
// Pin Connections Dataflash to Arduino Leonardo
//
//  DataFlash  Arduino Leonardo
//    pin 1  ---   pin 16
//    pin 2  ---   pin 15
//    pin 3  ---   pin  8
//    pin 4  ---   pin 10
//    pin 5  ---   pin  7
//    pin 6  ---   3.3V
//    pin 7  ---   GND
//    pin 8  ---   pin 14
//
// AT45DB161B Pin Layout
//         ___
//  SI  1 | u | 8 SO
//  SCK 2 |   | 7 GND
//  RST 3 |   | 6 VCC
//  CS  4 |___| 5 WP
//
// Arduino Leonardo ICSP Pin Layout
//
//              _____
//  D14 MISO 1 |__|__| 2 VDD
//  D15 SCK  3 |__|__| 4 MOSI D16
//      RST  5 |__|__| 6 GND
//
// This sketch is using blockos arduino-dataflash library available here:
// http://blockos.github.com/arduino-dataflash/
// and uses the arduino-timerone Library avaiable here:
// http://code.google.com/p/arduino-timerone/downloads/list
// Example by Taha Bintahir, http://mtaha.wordpress.com
//************************************************************************************


#include <DataFlash.h>
#include <TimerOne.h>
#include <SPI.h>

#define ledPin 13 // LED @ pin 13
#define baudRate 115200 // Baudrate for serial communication
#define timerIntterupt 1000 // Microsecond tick
#define lF 10 // ASCII Linefeed
#define msgLength 512 // Message Length

DataFlash dF; // DataFlash library object

unsigned long tickCounter = 0; // Tick counter used for subtimers
byte mode = 0; // 0 - default waiting mode, 1 - store mode, 2 - read mode

void setup(){
  uint8_t dFStatus;
  DataFlash::ID id;
 
  pinMode(ledPin, OUTPUT); // Initialise Led Pin
  digitalWrite(ledPin, LOW); // Ensure Led is turned OFF
 
  Serial.begin(baudRate); // Initialise Serial Communication @ 115200 bps
  SPI.begin(); // Initialise SPI
 
  Timer1.initialize(timerIntterupt); // Initialise Timer1 @ 1ms tick
  Timer1.attachInterrupt(timerIsr); // Initialise Timer1 Interrupt Subroutine function
 
  //delay(25000); // 25sec delay, allow us to press the serial monitor button and to compensate for the Leonardo to be detected by the PC
  while(!Serial){
    // Wait for serial port to connect. Needed for Leonardo only
  }
 
  dF.setup(10, 8, 7); // Initialise DataFlash SS - pin 10, RST - pin 8, WP - pin 7
 
  delay(10); // Settling time
 
  dFStatus = dF.status(); // Read status register
 
  dF.readID(id);
 
  // Display status register
  Serial.print("Status register :");
  Serial.print(dFStatus, BIN);
  Serial.print('\n');

  // Display manufacturer and device ID
  Serial.print("Manufacturer ID :\n");  // Should be 00011111
  Serial.print(id.manufacturer, HEX);
  Serial.print('\n');

  Serial.print("Device ID (part 1) :\n"); // Should be 100110
  Serial.print(id.device[0], HEX);
  Serial.print('\n');

  Serial.print("Device ID (part 2)  :\n"); // Should be 00000000
  Serial.print(id.device[1], HEX);
  Serial.print('\n');

  Serial.print("Extended Device Information String Length  :\n"); // 00000000
  Serial.print(id.extendedInfoLength, HEX);
  Serial.print('\n');
 
  Serial.println();
  Serial.println("Press 'S' to store data or press 'R' to read data"); 
   
}
void loop(){
  // Read Serial buffer only when there is data present
  if(Serial.available() > 0){
    uint16_t inByte = 0;
   
    inByte = Serial.read(); // Read Serial Buffer
    if(inByte != 0){
      // If 'S' byte is read
      if(inByte == 'S'){
        mode = 1; // Set state machine to mode 1
        Serial.println("What page do you want to store your data on?");
        while(1){
          // Store Data;
          if(Serial.available()){
            inByte = Serial.read();
            // If '`' is recieved exit out to main menu
            if(inByte == '`'){
              inByte = 0;
              mode = 0;
              mainMenu();
              break;
            }
            // Store data in page specified by user
            storeData(inByte);
            mainMenu();
            break;
          }
        }       
      }
      // if 'R' byte is read
      else if(inByte == 'R'){
        mode = 2; // Set state machine to mode 2
        Serial.println("What page do you want to read data from?");
        while(1){
          // Read Data
          if(Serial.available()){
            inByte = Serial.read();
            // If '`' is recieved exit out to main menu
            if(inByte == '`'){
              inByte = 0;
              mode = 0;
              mainMenu();
              break;
            }
            // Read data from user specified page
            readData(inByte);
            mainMenu();
            break;
          }
        }       
      }
    }
  }
}

// Timer1 Interrupt Subroutine Function triggered every 1ms
void timerIsr(){
  tickCounter++; // Count number of ticks
 
  // SubTimer1 @ 250ms
  if(tickCounter % 100 == 0){
    //Serial.println(mode);
    if(mode == 1){
      digitalWrite( ledPin, digitalRead(ledPin)^1 ); //  Blink LED every 250ms in Store mode
    }   
  }
 
  // SubTimer1 @ 500ms
  if(tickCounter % 500 == 0){
    //Serial.println(mode);
    if(mode == 2){
      digitalWrite( ledPin, digitalRead(ledPin)^1 ); // Blink LED every 500ms in Read mode
    }
  }
}

void mainMenu(){
  mode = 0; // Set state machine to default - 0
 
  // Check if led is turned ON if it is turn it OFF
  if(digitalRead(ledPin) == HIGH){
    digitalWrite(ledPin, LOW);
  }
 
  Serial.println();
  Serial.println("Press 'S' to store data or press 'R' to read data"); // Print main menu again
}

void storeData(uint16_t nPage){
  char msg[msgLength]; // Serial Read message buffer
  byte dataLength = 0; // Number of bytes recieved in the message
 
  Serial.println("Enter Data String: ");
  while(1){
    if(Serial.available()){
      dataLength = Serial.readBytesUntil('\n', msg, msgLength);
      break;     
    }   
  }
  msg[dataLength] = '\0'; // Terminate end of message with '\0' to easily find EOF
 
  dF.bufferWrite(1,0); // Select dataflash buffer 1 @ 0 offset
 
  // Transfer message to DataFlash Buffer
  for(int i = 0; msg[i] != '\0'; i++){
    SPI.transfer(msg[i]);
  }
 
  SPI.transfer('\0'); // Add '/0' to locate EOF within the DataFlash
 
  dF.bufferToPage(1, nPage); // Write DataFlash Buffer 1 to Pag
}

void readData(uint16_t nPage){
  uint8_t data; // Byte storage of data as recieved
 
  Serial.print('Page being read: ');
  Serial.println(nPage);
 
  dF.pageRead(nPage, 0); // Read user specified page from offset 0
 
  // Send FF to retrieve bytes from DataFlash
  do{
    data = SPI.transfer(0xff);
    if(data != '\0'){
      Serial.print(data);
    }
  }while(data != '\0');
 Serial.println();
}
2  Using Arduino / Storage / Dataflash AT45DB161D and Arduino Leonardo on: November 11, 2012, 01:59:24 am
Okay so i've been trying to get the at45db161d with the leonardo for the past couple of hours using the library available in the playground and haven't had much luck with it.
After looking online i realised that the SPI headders are no longer populated with the DIO headers instead they are on the ICSP header I modified the library to use those pins instead pointing them to:
MISO -  Digital 14   
SCK -   Digital 15   
MOSI - Digital 16

Since SS pin is not brought out on the leonardo I initially tried using just a regular DIO pin in my case D11, which didn't work. Next reading online I found out that the SS pin can be tapped into using the via just on top of RX Led and pointing the code to use D17; that hasn't worked either.

I've tested the flash using an Arduino Mega (Mega1280) and using its SPI headers and the flash is working without any issues with the Leonardo it hasn't worked. Any Ideas?
3  Using Arduino / Networking, Protocols, and Devices / Re: Arduino Slave to Arduino Master SPI on: May 20, 2011, 10:30:51 am
Okay so i may have come across another issue as you guys suggested i started looking into Ethernet to send the data across to the PC. i came across the WIZ811MJ Ethernet module it seems to be a popular one, that can be interfaced with the Ethernet Library. I noticed that it was that the WIZ811MJ also worked over the SPI protocol. Now i'm wondering would this cause any problems me?
4  Using Arduino / Networking, Protocols, and Devices / Re: Arduino Slave to Arduino Master SPI on: May 11, 2011, 09:53:46 am
I guess you are right i've been thinking it over all day yesterday, Ethernet with a simple chat server maybe the way to go it should be much faster for communication plus it'll give me additional bandwidth just in case for future expansion. So reading over everything you guys are recommending that i keep the parallel approach for acquiring data from the sensors to the slave arduino but i should go with a traditional master->slave hardware spi configuration for data concentration on the master arduino and ouput it all via ethernet? 
5  Using Arduino / Networking, Protocols, and Devices / Re: Arduino Slave to Arduino Master SPI on: May 10, 2011, 10:23:40 am
Quote
The drawing shows 8 sensors going to a single ADC, are they 8-input chips? What sample rate do you need?

At 8 bits each that's 1024 bits of data, have you done the maths? At the end of the day all this data has to get to a PC and AFAIK the fastest you can do this from an Arduino is 115200bps (via USB anyway, maybe using Ethernet would be faster).

Yes, I'm using a MCP3208 its a 8 Channel, 12-bit ADC. For my final prototype i intend to use 5390 sensors; however i plan to threshold sensor values to restrict the amount of data flow; Further more i plan limit the number of inputs to 30 which equates to about 175 sensors; this should decrease the bandwidth i need even further- 175*12*50 (number of sensors * bits per sensor * samples per second) = 105000bps this is under the 115200bps that the Arduino can output. So theoretically it should work.  
6  Using Arduino / Networking, Protocols, and Devices / Re: Arduino Slave to Arduino Master SPI on: May 09, 2011, 02:32:28 pm
One last thing, at the moment my prototype board has the following architecture where the SPI interface between the ADC and the Arduino is Bit Bang SPI using the bus architecture model as what i have posted above.

Now what i want to do is expand on this project by having multiple modules such as this sending data to the pc for that i though i'd use another arduino (just one as a master) that acts as a data concentrator to collect all the data from multiple modules and send it to the computer. After reading what you guys said, I'm just wondering would it be possible to change the Bit Bang SPI to hardware SPI while at the same time have the master arduino acting as a data concentrator on the same bus? it would kinda be like this:

Master Arduino -> Slave Arduino -> ADC -> Sensors
                      -> Slave Arduino -> ADC -> Sensors
.
.
.

Now another thing, would this be the best architecture for system, i want the design optimsed for speed i.e. the data which is received at the PC (the faster it is the better), i would think daisy chaining would be faster since you won't have the master communicating to each slave saying send me data.
7  Using Arduino / Networking, Protocols, and Devices / Re: Arduino Slave to Arduino Master SPI on: May 06, 2011, 02:07:10 pm
Thanks for all the information. After reading more i don't think theres a major advantage apart from saving pins if i were to go with Daisy Chaining. And since im using the Arduino Mega i'll more than enough pins. One thing i did come across and wanted more information on was the SS pin; the SPI hardware has only a single SS pin i presume to select other slaves on your BUS you can substitute the any DI pin as an SS pin to select a slave?
8  Using Arduino / Networking, Protocols, and Devices / Re: Arduino as SPI slave on: May 05, 2011, 01:23:49 pm
Shouldn't the MISO and MOSI pins be crossed over?
9  Using Arduino / Networking, Protocols, and Devices / Re: Arduino Slave to Arduino Master SPI on: May 05, 2011, 01:04:47 pm
I did notice a significant improvement over the standard technique; although both implementations i used bit bang to read the ADCs. I didn't do any measurements in terms of using a oscilloscope but i did notice a difference in my overall system. BTW i presume that the SPI library doesn't use bit bang and uses the spi hardware it self.
10  Using Arduino / Networking, Protocols, and Devices / Re: Arduino Slave to Arduino Master SPI on: May 05, 2011, 10:02:08 am
There is also this method i used this in the board to interface with multiple ADCs this allowed for polling of multiple ADCs in parallel of sorts. I wonder if this can work with Arduinos.

This is more of a variation to the traditional bus design; SCLK, MOSI and SS are all common and MISO is not.
11  Using Arduino / Networking, Protocols, and Devices / Re: Arduino Slave to Arduino Master SPI on: May 04, 2011, 02:49:55 pm
I don't know if you've seen this http://arduino.cc/blog/2010/10/25/multi-touch-input-sensor-based-of-arduino-mega/ i made this over a year ago and i plan to expand on to it now i was thinking about creating a cascading system utilizing arduinos and i'm just working out the best implementation for this expansion i had 2 ideas either to create a traditional SPI Master slave configuration where the master polls individual slaves for information and which it then processes and sends to the computer or to user a daisy chain where the data is collected from all arduinos then sent to a master controller in one swoop which is then processed and sent to the pc.
12  Using Arduino / Networking, Protocols, and Devices / Arduino Slave to Arduino Master SPI & WIZ811MJ on: May 04, 2011, 08:52:05 am
Hi was wondering is there any code any for Slave to Master data transfer using 2 Arduinos using SPI. Also what about daisy-chain SPI using arduinos?
13  Forum 2005-2010 (read only) / Troubleshooting / Re: Cannot upload on Arduino Duemilanove on: November 21, 2010, 05:02:25 am
I was having the same problem the other day... then i found a thread on the forums here explaining how to fix it dont have the thread on me. But this is the process to fix it i used to fix my arduino
This usually works with a large sketch.
1) unplug your arduino
2) hold the reset button down and plug it back in
3) while holding the reset button press the upload button in the Arduino IDE
4) as soon as it compiles the sketch and begins uploading release the the reset pin
5) you should see Tx and Rx leds blink if it works your sketch would have uploaded if you mistimed it then it'll give you the same error.

This usually happens when a sketch isnt uploaded properly.
hope this helps
14  Forum 2005-2010 (read only) / Troubleshooting / Re: Global disable pull-up resistors Arduino Mega on: November 21, 2010, 03:59:31 am
Well its done something but its not behaving the way i was expecting so cant say if its really working or not, there may be a bug in my code.
15  Forum 2005-2010 (read only) / Troubleshooting / Global disable pull-up resistors Arduino Mega on: November 21, 2010, 03:39:16 am
Hi i was wondering how to global disable pull up resistors on the arduino mega 1280.
I've tried _SFR_IO8(0x35) |= 0x10; but it seems not to work any suggestions on how to get it working?
Pages: [1] 2