Pages: [1]   Go Down
Author Topic: problem with sdcard and sram 23LC1024  (Read 542 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Connecting sd card (http://www.hobbytronics.co.uk/microsd-card-regulated-v2) and sram 23LC1024 so SPI data written to ram are wrong, (I write all the data in RAM are wrong)

I have read many posts in the forum, many people have this problem, but I could not find the solution to the problem of multiple spi

someone has an idea?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49343
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
someone has an idea?
Post your code. Explain how you know that the data written is wrong.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
thanks for the reply.

you describe the problem:
Sending data with Bluetooth Arduino mini to correctly receive the data, writing the data received in memory, while the readDataFromRam function () read from memory the received data and print data.

For example, sending the characters:

x
y
z
w

the data read from the memory does not match the characters.


I think it's a problem because I use two SPI.

configuration that I use:

- Arduino Mini V05

- Sram 23LC1024 (microchip), with this configuration
http://ucexperiment.wordpress.com/2013/02/26/more-memory-arduino-and-23lc1024/

(my SS pin is 10)

- Micro sd
http://www.hobbytronics.co.uk/microsd-card-regulated-v2
(my SS is 9)


Below is the code for that use.
(
  does not work with this code
http://ucexperiment.wordpress.com/2013/02/26/more-memory-arduino-and-23lc1024
)

If I remove the micro sd, then it works


code

------------------------------------------------




 
#include <avr/pgmspace.h>
#include  <SPI.h>

int printer_RX_Pin = 6;  
int printer_TX_Pin = 7;  

const int rxPin = 4;
const int txPin = 5;
const int atPin = 3;

const int bSize = 80;
int ByteCount;
char Buffer[bSize];

 //SRAM opcodes
#define RDSR        5
#define WRSR        1
#define READ        3
#define WRITE       2


# define DATAOUT 11 / / MOSI
# define DATAIN 12 / / MISO
# define SPICLOCK 13 / / SCK

uint32_t addressIncrementale=0;
const long timeout = 10000;  //abbassare tempo di non ricezione
int finished=0;

SoftwareSerial bluetooth(rxPin, txPin);  //IDE >= 1.0
 

        
void setup()
{
    Serial.begin(9600);
    initParam();
    bluetooth.begin(9600);
    startOperations();
}
 
 
void initParam()
  {
    initParam_zero();
    pinMode(10, OUTPUT);
    pinMode(9, OUTPUT);
    
    pinMode(8, INPUT_PULLUP);
    
    digitalWrite(9, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(10, HIGH);
    
    SPI.begin();
    SPI.setClockDivider(4);
    
  
    digitalWrite(8, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(10,LOW);
  }
  
 
 void initParam_zero()
 {

   pinMode ( SCK , OUTPUT ) ;
   pinMode ( MOSI , OUTPUT ) ;
   digitalWrite ( SCK , LOW ) ;
   digitalWrite ( MOSI , LOW ) ;

 }

  
  
void startOperations()
{
  int  val=digitalRead(8);
  (if you pressed the button calls procedure ...)

  startReceivingData();
  if(finished==1)
  {
    readDataFromRam();
  }
  
}  
  

void startReceivingData()
{
     while(1)
     {
        readByte();
        while (!bluetooth.available())
{
 ......
5 seconds after that I do not get out of the while loop  
         and sets flag finished=1
        }
     }
}  

void readByte()
{
   ByteCount = -1;
   ByteCount =  bluetooth.readBytes(Buffer,bSize-1);
   if (ByteCount  > 0)
   {
     for( int k=0;k < ByteCount; k++)
     {
       Spi23LC1024Write8(addressIncrementale, (uint8_t) Buffer[k]);
       addressIncrementale++;
      }  
    }
  memset(Buffer, '\0', sizeof(Buffer));   // Clear contents of Buffer
}
 
  
  
void readDataFromRam()
{
  for ( uint32_t y=0;y< addressIncrementale;y++)
  {
      uint8_t  data= (uint8_t )Spi23LC1024Read8(y);
      Serial.print((char)data);
  
   }
  }
  
 
  
void loop()
{
  
}
 
  
    

 
 
    

 //Byte transfer functions
uint8_t Spi23LC1024Read8(uint32_t address) {
  uint8_t read_byte;
 
  PORTB &= ~(1<<PORTB2);        //set SPI_SS low
  SPI.transfer(READ);
  SPI.transfer((uint8_t)(address >> 16) & 0xff);
  SPI.transfer((uint8_t)(address >> 8) & 0xff);
  SPI.transfer((uint8_t)address);
  read_byte = SPI.transfer(0x00);
  PORTB |= (1<<PORTB2);         //set SPI_SS high
  return read_byte;
  
}
  
void Spi23LC1024Write8(uint32_t address, uint8_t data_byte) {
  PORTB &= ~(1<<PORTB2);        //set SPI_SS low
  SPI.transfer(WRITE);
  SPI.transfer((uint8_t)(address >> 16) & 0xff);
  SPI.transfer((uint8_t)(address >> 8) & 0xff);
  SPI.transfer((uint8_t)address);
  SPI.transfer(data_byte);
  PORTB |= (1<<PORTB2);         //set SPI_SS high
}


    
  
 

------------------------------------------------
« Last Edit: March 26, 2014, 06:01:52 am by pafra » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49343
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you can't be bothered to post code correctly, I can't be bothered to read it.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello,
I'm sorry but I have not seen that in my post were present smile instead of the number 8.

I am attaching the code below.

Yesterday I made other tests with Arduino one works properly.

Arduino one works correctly without setting SPI.setClockDivider,
while with Arduino mini I'm forced to set SPI.setClockDivider (4) otherwise it does not work.

----------------------------
#include <avr/pgmspace.h>
#include  <SPI.h>

int printer_RX_Pin = 6; 
int printer_TX_Pin = 7; 

const int rxPin = 4;
const int txPin = 5;
const int atPin = 3;

const int bSize = 80;
int ByteCount;
char Buffer[bSize];

 //SRAM opcodes
#define RDSR        5
#define WRSR        1
#define READ        3
#define WRITE       2


# define DATAOUT 11 / / MOSI
# define DATAIN 12 / / MISO
# define SPICLOCK 13 / / SCK

uint32_t addressIncrementale=0;
const long timeout = 10000;  //abbassare tempo di non ricezione
int finished=0;

SoftwareSerial bluetooth(rxPin, txPin);  //IDE >= 1.0
 

       
void setup()
{
    Serial.begin(9600);
    initParam();
    bluetooth.begin(9600);
    startOperations();
}
 
 
void initParam()
  {
    initParam_zero();
    pinMode(10, OUTPUT);
    pinMode(9, OUTPUT);
   
    pinMode(8, INPUT_PULLUP);
   
    digitalWrite(9, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(10, HIGH);
     
    SPI.begin();
    SPI.setClockDivider(4);
   
 
    digitalWrite(8, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(10,LOW);
  }
   
 
 void initParam_zero()
 {

   pinMode ( SCK , OUTPUT ) ;
   pinMode ( MOSI , OUTPUT ) ;
   digitalWrite ( SCK , LOW ) ;
   digitalWrite ( MOSI , LOW ) ;

 }

    int val_8=8;   
 
void startOperations()
{
  int  val=digitalRead(val_8);
    if (digitalRead(val_8)==0)
      procedurePrint();
 
  startReceivingData();
  if(finished==1)
  {
    readDataFromRam();
  }
 

 
int notReady=0;
void startReceivingData()
{
     while(1)
     {
        readByte();
        while (!bluetooth.available())
        {
            notReady++;
            if (notReady==10000)
            {
              finished=1;           
              break;
            }

        }
     }


void readByte()
{
   ByteCount = -1;
   ByteCount =  bluetooth.readBytes(Buffer,bSize-1);
   if (ByteCount  > 0)
   {
     for( int k=0;k < ByteCount; k++)
     {
       Spi23LC1024Write8(addressIncrementale, (uint8_t) Buffer[k]);
       addressIncrementale++;
      }     
    }
  memset(Buffer, '\0', sizeof(Buffer));   // Clear contents of Buffer
}
 
 
 
void readDataFromRam()
{
  for ( uint32_t y=0;y< addressIncrementale;y++)
  {
      uint8_t  data= (uint8_t )Spi23LC1024Read8(y);
      Serial.print((char)data);
   
   }
  }
 
 
 
void loop()
{
   
}
 
 
     

 
 


 //Byte transfer functions
uint8_t Spi23LC1024Read8(uint32_t address) {
  uint8_t read_byte;
 
  PORTB &= ~(1<<PORTB2);        //set SPI_SS low
  SPI.transfer(READ);
  SPI.transfer((uint8_t)(address >> 16) & 0xff);
  SPI.transfer((uint8_t)(address >>  val_8) & 0xff);
  SPI.transfer((uint8_t)address);
  read_byte = SPI.transfer(0x00);
  PORTB |= (1<<PORTB2);         //set SPI_SS high
  return read_byte;
 
}
 
void Spi23LC1024Write8(uint32_t address, uint8_t data_byte) {
  PORTB &= ~(1<<PORTB2);        //set SPI_SS low
  SPI.transfer(WRITE);
  SPI.transfer((uint8_t)(address >> 16) & 0xff);
  SPI.transfer((uint8_t)(address >> val_8) & 0xff);
  SPI.transfer((uint8_t)address);
  SPI.transfer(data_byte);
  PORTB |= (1<<PORTB2);         //set SPI_SS high
}
-----------------


« Last Edit: March 26, 2014, 04:55:16 am by pafra » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49343
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am attaching the code below.
Still incorrectly. Modify your post. Select all the code. Select the # button above the row of smiley faces. Save the changes. See the pretty code box?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello,
I'm sorry but I have not seen that in my post were present smile instead of the number 8.

I am attaching the code below.

Yesterday I made other tests with Arduino one works properly.

Arduino one works correctly without setting SPI.setClockDivider,
while with Arduino mini I'm forced to set SPI.setClockDivider (4) otherwise it does not work.

----------------------------
#include <avr/pgmspace.h>
#include  <SPI.h>

int printer_RX_Pin = 6; 
int printer_TX_Pin = 7; 

const int rxPin = 4;
const int txPin = 5;
const int atPin = 3;

const int bSize = 80;
int ByteCount;
char Buffer[bSize];

 //SRAM opcodes
#define RDSR        5
#define WRSR        1
#define READ        3
#define WRITE       2


# define DATAOUT 11 / / MOSI
# define DATAIN 12 / / MISO
# define SPICLOCK 13 / / SCK

uint32_t addressIncrementale=0;
const long timeout = 10000;  //abbassare tempo di non ricezione
int finished=0;

SoftwareSerial bluetooth(rxPin, txPin);  //IDE >= 1.0
 

       
void setup()
{
    Serial.begin(9600);
    initParam();
    bluetooth.begin(9600);
    startOperations();
}
 
 
void initParam()
  {
    initParam_zero();
    pinMode(10, OUTPUT);
    pinMode(9, OUTPUT);
   
    pinMode(8, INPUT_PULLUP);
   
    digitalWrite(9, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(10, HIGH);
     
    SPI.begin();
    SPI.setClockDivider(4);
   
 
    digitalWrite(8, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(10,LOW);
  }
   
 
 void initParam_zero()
 {

   pinMode ( SCK , OUTPUT ) ;
   pinMode ( MOSI , OUTPUT ) ;
   digitalWrite ( SCK , LOW ) ;
   digitalWrite ( MOSI , LOW ) ;

 }

    int val_8=8;   
 
void startOperations()
{
  int  val=digitalRead(val_8);
    if (digitalRead(val_8)==0)
      procedurePrint();
 
  startReceivingData();
  if(finished==1)
  {
    readDataFromRam();
  }
 

 
int notReady=0;
void startReceivingData()
{
     while(1)
     {
        readByte();
        while (!bluetooth.available())
        {
            notReady++;
            if (notReady==10000)
            {
              finished=1;           
              break;
            }

        }
     }


void readByte()
{
   ByteCount = -1;
   ByteCount =  bluetooth.readBytes(Buffer,bSize-1);
   if (ByteCount  > 0)
   {
     for( int k=0;k < ByteCount; k++)
     {
       Spi23LC1024Write8(addressIncrementale, (uint8_t) Buffer[k]);
       addressIncrementale++;
      }     
    }
  memset(Buffer, '\0', sizeof(Buffer));   // Clear contents of Buffer
}
 
 
 
void readDataFromRam()
{
  for ( uint32_t y=0;y< addressIncrementale;y++)
  {
      uint8_t  data= (uint8_t )Spi23LC1024Read8(y);
      Serial.print((char)data);
   
   }
  }
 
 
 
void loop()
{
   
}
 
 
     

 
 


 //Byte transfer functions
uint8_t Spi23LC1024Read8(uint32_t address) {
  uint8_t read_byte;
 
  PORTB &= ~(1<<PORTB2);        //set SPI_SS low
  SPI.transfer(READ);
  SPI.transfer((uint8_t)(address >> 16) & 0xff);
  SPI.transfer((uint8_t)(address >>  val_8) & 0xff);
  SPI.transfer((uint8_t)address);
  read_byte = SPI.transfer(0x00);
  PORTB |= (1<<PORTB2);         //set SPI_SS high
  return read_byte;
 
}
 
void Spi23LC1024Write8(uint32_t address, uint8_t data_byte) {
  PORTB &= ~(1<<PORTB2);        //set SPI_SS low
  SPI.transfer(WRITE);
  SPI.transfer((uint8_t)(address >> 16) & 0xff);
  SPI.transfer((uint8_t)(address >> val_8) & 0xff);
  SPI.transfer((uint8_t)address);
  SPI.transfer(data_byte);
  PORTB |= (1<<PORTB2);         //set SPI_SS high
}
-----------------



Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have attached the file, to make sure you have the correct font formatting..
thanks

* test_arduino_mini.ini (3.17 KB - downloaded 13 times.)
Logged

Pages: [1]   Go Up
Jump to: