Show Posts
Pages: [1] 2
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: I²C Memory Card Help. Cant Write more than one bit on: September 29, 2010, 04:47:15 am
Well. I haven't tried the new option because I'm waiting for smart-card connectors to arrive from China. With these i can be assured that the connection to the device is fine. I will update when i receive them. According to the company it should be some time next week.
2  Forum 2005-2010 (read only) / Syntax & Programs / Re: I²C Memory Card Help. Cant Write more than one bit on: September 24, 2010, 12:24:52 pm
i am not following. I have had a look at the writing and reading section of the datasheet. I dont understand how it is done. Can anyone help me.
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: I²C Memory Card Help. Cant Write more than one bit on: September 24, 2010, 01:41:25 am
ok. now i have this code:

Code:
#include <Wire.h>

void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
  int rdata = data;
  Wire.beginTransmission(deviceaddress);
    Wire.send((byte)(eeaddress >> 8)); // MSB
   Wire.send((byte)eeaddress&255);
  Wire.send(rdata);
  Wire.endTransmission();
}

// WARNING: address is a page address, 6-bit end will wrap around
// also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length ) {
  Wire.beginTransmission(deviceaddress);
    Wire.send((byte)(eeaddresspage >> 8)); // MSB
   Wire.send((byte)eeaddresspage&255);



  byte c;
  for ( c = 0; c < length; c++)
    Wire.send(data[c]);
  Wire.endTransmission();
}

byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
  byte rdata = 0xFF;
  Wire.beginTransmission(deviceaddress);
    Wire.send((byte)(eeaddress >> 8)); // MSB
  Wire.send((byte)eeaddress&255); // LSB
  Wire.endTransmission();
  Wire.requestFrom(deviceaddress,1);
  if (Wire.available()) rdata = Wire.receive();
  return rdata;
}

// maybe let's not read more than 30 or 32 bytes at a time!
void i2c_eeprom_read_buffer( int deviceaddress, unsigned int eeaddress, byte *buffer, int length ) {
  Wire.beginTransmission(deviceaddress);
   Wire.send((byte)(eeaddress >> 8)); // MSB
  Wire.send((byte)eeaddress&255); // LSB
  Wire.endTransmission();
  Wire.requestFrom(deviceaddress,length);
  int c = 0;
  for ( c = 0; c < length; c++ )
    if (Wire.available()) buffer[c] = Wire.receive();
}


void setup()
{
  Wire.begin();
  Serial.begin(9600);
  
  i2c_eeprom_write_byte(0x50,00,145);
  delay(50);
    i2c_eeprom_write_byte(0x50,01,146);
  delay(50);
    i2c_eeprom_write_byte(0x50,02,147);
  delay(50);
    i2c_eeprom_write_byte(0x50,03,148);
  delay(50);
    i2c_eeprom_write_byte(0x50,04,149);
  delay(50);
    i2c_eeprom_write_byte(0x50,05,150);
  delay(50);
  Serial.println("DOne");
  
}
 int n = 0;
void loop()
{

}

It seems that no matter what address i use as eeaddress the writing is done to byte 0

How can i fix this?
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: I²C Memory Card Help. Cant Write more than one bit on: September 23, 2010, 08:40:46 pm
Code:
#include <Wire.h>

void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
  int rdata = data;
  Wire.beginTransmission(deviceaddress);
    Wire.send((byte)(eeaddress >> 8)); // MSB
   Wire.send((byte)eeaddress&255);
  Wire.send(rdata);
  Wire.endTransmission();
}

// WARNING: address is a page address, 6-bit end will wrap around
// also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length ) {
  Wire.beginTransmission(deviceaddress);
    Wire.send((byte)(eeaddresspage >> 8)); // MSB
   Wire.send((byte)eeaddresspage&255);

 

  byte c;
  for ( c = 0; c < length; c++)
    Wire.send(data[c]);
  Wire.endTransmission();
}

byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
  byte rdata = 0xFF;
  Wire.beginTransmission(deviceaddress);
    Wire.send((byte)(eeaddress >> 8)); // MSB
  Wire.send((byte)eeaddress&255); // LSB
  Wire.endTransmission();
  Wire.requestFrom(deviceaddress,1);
  if (Wire.available()) rdata = Wire.receive();
  return rdata;
}

// maybe let's not read more than 30 or 32 bytes at a time!
void i2c_eeprom_read_buffer( int deviceaddress, unsigned int eeaddress, byte *buffer, int length ) {
  Wire.beginTransmission(deviceaddress);
   Wire.send((byte)(eeaddress >> 8)); // MSB
  Wire.send((byte)eeaddress&255); // LSB
  Wire.endTransmission();
  Wire.requestFrom(deviceaddress,length);
  int c = 0;
  for ( c = 0; c < length; c++ )
    if (Wire.available()) buffer[c] = Wire.receive();
}


void setup()
{
  Wire.begin();
  Serial.begin(9600);
}
 int n = 0;
void loop()
{
 for(int x = 0;x<256;x++){
  
   i2c_eeprom_write_byte(0x50,x,0x2);
   delay(50);
   Serial.print("wrote: ");
   Serial.println(x);
  
 }
   Serial.println("done1");
 delay(10000);

}

here it is?

Ive tried writing but it doesnt work.
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: I²C Memory Card Help. Cant Write more than one bit on: September 23, 2010, 05:27:02 pm
Thanks for the reply.

How should i fix that problem?

Im really confused.
6  Forum 2005-2010 (read only) / Syntax & Programs / Re: I²C Memory Card Help. Cant Write more than one bit on: September 23, 2010, 02:21:46 pm
ok. I will change that. But can you tell me why its not reading like it should be?
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: I²C Memory Card Help. Cant Write more than one bit on: September 23, 2010, 05:38:24 am
Now i have edited my program:

here is the new one:

Code:
#include <Wire.h>


void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
  delay(3000);
}
int a;
void loop()
{
 
 delay(50);
  Serial.println("Entering Loops");

  for(int z = 0;z<7;z++){
    Wire.requestFrom(0x50,32);
   for(int i = 0; i<32;i++){
    byte rdata;
    
     if (Wire.available()){
        rdata = Wire.receive();
      }else{
        Serial.print("Breaking after : ");
        Serial.print(a);
        Serial.println(" Bytes");
        break;
      }
      Serial.print("Byte(");
      Serial.print(a);
      Serial.print(") ");
    Serial.print(i);
    Serial.print(" : ");
   Serial.println(rdata,HEX);
    a++;
 }
 
 Serial.print("Loop: ");
 Serial.print(z);
 Serial.println(" Done");
 
 }
 delay(2000);
 Serial.println("getting last set");
 
 Wire.requestFrom(0x50,31);
 for(int q = 0;q<31;q++){
  byte date;
  
     if (Wire.available()){
        date = Wire.receive();
      }else{
        Serial.print("No Data");
      }
      Serial.print("Byte(");
      Serial.print(a);
      Serial.print(") ");
    Serial.print(q);
    Serial.print(" : ");
   Serial.println(date,HEX);
   a++;
  
   if(a == 255){
     Serial.println("Fully DOne");
     delay(20000);}
}
}

and here is the out put i am getting:

Code:
Entering Loops
Byte(0) 0 : 1D
Byte(1) 1 : 2
Byte(2) 2 : 3A
Byte(3) 3 : 3B
Byte(4) 4 : 3C
Byte(5) 5 : 35
Byte(6) 6 : 36
Byte(7) 7 : 37
Byte(8) 8 : FF
Byte(9) 9 : FF
Byte(10) 10 : FF
Byte(11) 11 : FF
Byte(12) 12 : FF
Byte(13) 13 : FF
Byte(14) 14 : FF
Byte(15) 15 : FF
Byte(16) 16 : FF
Byte(17) 17 : FF
Byte(18) 18 : FF
Byte(19) 19 : FF
Byte(20) 20 : FF
Byte(21) 21 : FF
Byte(22) 22 : FF
Byte(23) 23 : FF
Byte(24) 24 : FF
Byte(25) 25 : FF
Byte(26) 26 : FF
Byte(27) 27 : FF
Byte(28) 28 : FF
Byte(29) 29 : FF
Byte(30) 30 : FF
Byte(31) 31 : FF
Loop: 0 Done
Byte(32) 0 : FF
Byte(33) 1 : FF
Byte(34) 2 : FF
Byte(35) 3 : FF
Byte(36) 4 : FF
Byte(37) 5 : FF
Byte(38) 6 : FF
Byte(39) 7 : FF
Byte(40) 8 : FF
Byte(41) 9 : FF
Byte(42) 10 : FF
Byte(43) 11 : FF
Byte(44) 12 : FF
Byte(45) 13 : FF
Byte(46) 14 : FF
Byte(47) 15 : FF
Byte(48) 16 : FF
Byte(49) 17 : FF
Byte(50) 18 : FF
Byte(51) 19 : FF
Byte(52) 20 : FF
Byte(53) 21 : FF
Byte(54) 22 : FF
Byte(55) 23 : FF
Byte(56) 24 : FF
Byte(57) 25 : FF
Byte(58) 26 : FF
Byte(59) 27 : FF
Byte(60) 28 : FF
Byte(61) 29 : FF
Byte(62) 30 : FF
Byte(63) 31 : FF
Loop: 1 Done
Byte(64) 0 : FF
Byte(65) 1 : FF
Byte(66) 2 : FF
Byte(67) 3 : FF
Byte(68) 4 : FF
Byte(69) 5 : FF
Byte(70) 6 : FF
Byte(71) 7 : FF
Byte(72) 8 : FF
Byte(73) 9 : FF
Byte(74) 10 : FF
Byte(75) 11 : FF
Byte(76) 12 : FF
Byte(77) 13 : FF
Byte(78) 14 : FF
Byte(79) 15 : FF
Byte(80) 16 : FF
Byte(81) 17 : FF
Byte(82) 18 : FF
Byte(83) 19 : FF
Byte(84) 20 : FF
Byte(85) 21 : FF
Byte(86) 22 : FF
Byte(87) 23 : FF
Byte(88) 24 : FF
Byte(89) 25 : FF
Byte(90) 26 : FF
Byte(91) 27 : FF
Byte(92) 28 : FF
Byte(93) 29 : FF
Byte(94) 30 : FF
Byte(95) 31 : FF
Loop: 2 Done
Byte(96) 0 : FF
Byte(97) 1 : FF
Byte(98) 2 : FF
Byte(99) 3 : FF
Byte(100) 4 : FF
Byte(101) 5 : FF
Byte(102) 6 : FF
Byte(103) 7 : FF
Byte(104) 8 : FF
Byte(105) 9 : FF
Byte(106) 10 : FF
Byte(107) 11 : FF
Byte(108) 12 : FF
Byte(109) 13 : FF
Byte(110) 14 : FF
Byte(111) 15 : FF
Byte(112) 16 : FF
Byte(113) 17 : FF
Byte(114) 18 : FF
Byte(115) 19 : FF
Byte(116) 20 : FF
Byte(117) 21 : FF
Byte(118) 22 : FF
Byte(119) 23 : FF
Byte(120) 24 : FF
Byte(121) 25 : FF
Byte(122) 26 : FF
Byte(123) 27 : FF
Byte(124) 28 : FF
Byte(125) 29 : FF
Byte(126) 30 : FF
Byte(127) 31 : FF
Loop: 3 Done
Byte(128) 0 : FF
Byte(129) 1 : FF
Byte(130) 2 : FF
Byte(131) 3 : FF
Byte(132) 4 : FF
Byte(133) 5 : FF
Byte(134) 6 : FF
Byte(135) 7 : FF
Byte(136) 8 : FF
Byte(137) 9 : FF
Byte(138) 10 : FF
Byte(139) 11 : FF
Byte(140) 12 : FF
Byte(141) 13 : FF
Byte(142) 14 : FF
Byte(143) 15 : FF
Byte(144) 16 : FF
Byte(145) 17 : FF
Byte(146) 18 : FF
Byte(147) 19 : FF
Byte(148) 20 : FF
Byte(149) 21 : FF
Byte(150) 22 : FF
Byte(151) 23 : FF
Byte(152) 24 : FF
Byte(153) 25 : FF
Byte(154) 26 : FF
Byte(155) 27 : FF
Byte(156) 28 : FF
Byte(157) 29 : FF
Byte(158) 30 : FF
Byte(159) 31 : FF
Loop: 4 Done
Byte(160) 0 : FF
Byte(161) 1 : FF
Byte(162) 2 : FF
Byte(163) 3 : FF
Byte(164) 4 : FF
Byte(165) 5 : FF
Byte(166) 6 : FF
Byte(167) 7 : FF
Byte(168) 8 : FF
Byte(169) 9 : FF
Byte(170) 10 : FF
Byte(171) 11 : FF
Byte(172) 12 : FF
Byte(173) 13 : FF
Byte(174) 14 : FF
Byte(175) 15 : FF
Byte(176) 16 : FF
Byte(177) 17 : FF
Byte(178) 18 : FF
Byte(179) 19 : FF
Byte(180) 20 : FF
Byte(181) 21 : FF
Byte(182) 22 : FF
Byte(183) 23 : FF
Byte(184) 24 : FF
Byte(185) 25 : FF
Byte(186) 26 : FF
Byte(187) 27 : FF
Byte(188) 28 : FF
Byte(189) 29 : FF
Byte(190) 30 : FF
Byte(191) 31 : FF
Loop: 5 Done
Byte(192) 0 : FF
Byte(193) 1 : FF
Byte(194) 2 : FF
Byte(195) 3 : FF
Byte(196) 4 : FF
Byte(197) 5 : FF
Byte(198) 6 : FF
Byte(199) 7 : FF
Byte(200) 8 : FF
Byte(201) 9 : FF
Byte(202) 10 : FF
Byte(203) 11 : FF
Byte(204) 12 : FF
Byte(205) 13 : FF
Byte(206) 14 : FF
Byte(207) 15 : FF
Byte(208) 16 : FF
Byte(209) 17 : FF
Byte(210) 18 : FF
Byte(211) 19 : FF
Byte(212) 20 : FF
Byte(213) 21 : FF
Byte(214) 22 : FF
Byte(215) 23 : FF
Byte(216) 24 : FF
Byte(217) 25 : FF
Byte(218) 26 : FF
Byte(219) 27 : FF
Byte(220) 28 : FF
Byte(221) 29 : FF
Byte(222) 30 : FF
Byte(223) 31 : FF
Loop: 6 Done
getting last set
Byte(224) 0 : FF
Byte(225) 1 : FF
Byte(226) 2 : FF
Byte(227) 3 : FF
Byte(228) 4 : FF
Byte(229) 5 : FF
Byte(230) 6 : FF
Byte(231) 7 : FF
Byte(232) 8 : FF
Byte(233) 9 : FF
Byte(234) 10 : FF
Byte(235) 11 : FF
Byte(236) 12 : FF
Byte(237) 13 : FF
Byte(238) 14 : FF
Byte(239) 15 : FF
Byte(240) 16 : FF
Byte(241) 17 : FF
Byte(242) 18 : FF
Byte(243) 19 : FF
Byte(244) 20 : FF
Byte(245) 21 : FF
Byte(246) 22 : FF
Byte(247) 23 : FF
Byte(248) 24 : FF
Byte(249) 25 : FF
Byte(250) 26 : FF
Byte(251) 27 : FF
Byte(252) 28 : FF
Byte(253) 29 : FF
Byte(254) 30 : FF

but this is the real dump when i do it by a program that i know can read this card (but i cant use it to write):

Code:
00000000 02 3a 3b 3c 35 36 37 ff ff ff ff ff ff ff ff ff .:;<567ÿÿÿÿÿÿÿÿÿ
00000010 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000030 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000040 02 3a 3b 3c 35 36 37 ff ff ff ff ff ff ff ff ff .:;<567ÿÿÿÿÿÿÿÿÿ
00000050 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000060 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000080 02 3a 3b 3c 35 36 37 ff ff ff ff ff ff ff ff ff .:;<567ÿÿÿÿÿÿÿÿÿ
00000090 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
000000a0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
000000b0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
000000c0 02 3a 3b 3c 35 36 37 ff ff ff ff ff ff ff ff ff .:;<567ÿÿÿÿÿÿÿÿÿ
000000d0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
000000e0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
000000f0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000100 3a 3b 3c 35 36 37 ff ff ff ff ff ff ff ff ff ff :;<567ÿÿÿÿÿÿÿÿÿÿ
00000110 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000120 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000130 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000140 3a 3b 3c 35 36 37 ff ff ff ff ff ff ff ff ff ff :;<567ÿÿÿÿÿÿÿÿÿÿ
00000150 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000160 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000170 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000180 3a 3b 3c 35 36 37 ff ff ff ff ff ff ff ff ff ff :;<567ÿÿÿÿÿÿÿÿÿÿ
00000190 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
000001a0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
000001b0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
000001c0 3a 3b 3c 35 36 37 ff ff ff ff ff ff ff ff ff ff :;<567ÿÿÿÿÿÿÿÿÿÿ
000001d0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
000001e0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
000001f0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000200 3b 3c 35 36 37 ff ff ff ff ff ff ff ff ff ff ff ;<567ÿÿÿÿÿÿÿÿÿÿÿ
00000210 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000220 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000230 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000240 3b 3c 35 36 37 ff ff ff ff ff ff ff ff ff ff ff ;<567ÿÿÿÿÿÿÿÿÿÿÿ
00000250 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000260 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000270 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
00000280 3b 3c 35 36 37 ff ff ff ff ff ff ff ff ff ff ff ;<567ÿÿÿÿÿÿÿÿÿÿÿ
00000290 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
000002a0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
000002b0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
000002c0 3b 3c 35 36 37 ff ff ff ff ff ff ff ff ff ff ff ;<567ÿÿÿÿÿÿÿÿÿÿÿ
000002d0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ


Pleas help me!! Anyone?
8  Forum 2005-2010 (read only) / Syntax & Programs / Re: I²C Memory Card Help. Cant Write more than one bit on: September 21, 2010, 08:01:47 pm
ok. i got some where. But now when i want to write to the last byte (255) the first byte (0) is changed not the last one.

Can anyone please help me?
9  Forum 2005-2010 (read only) / Syntax & Programs / Re: I²C Memory Card Help. Cant Write more than one bit on: September 20, 2010, 05:56:36 am
so how can i read the whole 255 bytes? and write to them?
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: I²C Memory Card Help. Cant Write more than one bit on: September 20, 2010, 05:47:31 am
Im sorry deSilva i do not understand what you just said.
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: I²C Memory Card Help. Cant Write more than one bit on: September 20, 2010, 05:44:00 am
Thanks ben, i have edited my code now. I have the out below. I am really stuck. Can you please have a look? Ive tried everything basically. Powering the card on and off between reading and writing, not power cycling etc...


Here is writing code:

Code:
#include <Wire.h>

void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
  int rdata = data;
  Wire.beginTransmission(deviceaddress);
    Wire.send((byte)(eeaddress >> 8)); // MSB
  Wire.send((byte)eeaddress); // LSB
  Wire.send(rdata);
  Wire.endTransmission();
}

// WARNING: address is a page address, 6-bit end will wrap around
// also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length ) {
  Wire.beginTransmission(deviceaddress);
    Wire.send((byte)(eeaddresspage >> 8)); // MSB
  Wire.send((byte)eeaddresspage); // LSB
 

  byte c;
  for ( c = 0; c < length; c++)
    Wire.send(data[c]);
  Wire.endTransmission();
}

byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
  byte rdata = 0xFF;
  Wire.beginTransmission(deviceaddress);
    Wire.send((byte)(eeaddress >> 8)); // MSB
  Wire.send((byte)eeaddress); // LSB
  Wire.endTransmission();
  Wire.requestFrom(deviceaddress,1);
  if (Wire.available()) rdata = Wire.receive();
  return rdata;
}

// maybe let's not read more than 30 or 32 bytes at a time!
void i2c_eeprom_read_buffer( int deviceaddress, unsigned int eeaddress, byte *buffer, int length ) {
  Wire.beginTransmission(deviceaddress);
   Wire.send((byte)(eeaddress >> 8)); // MSB
  Wire.send((byte)eeaddress); // LSB
  Wire.endTransmission();
  Wire.requestFrom(deviceaddress,length);
  int c = 0;
  for ( c = 0; c < length; c++ )
    if (Wire.available()) buffer[c] = Wire.receive();
}


void setup()
{
  Wire.begin();
  Serial.begin(9600);
}
 int n = 0;
void loop()
{
 for(int x = 0;x<256;x++){
  
   i2c_eeprom_write_byte(0x50,x,0x2);
   delay(50);
   Serial.print("wrote: ");
   Serial.println(x);
  
 }
   Serial.println("done1");
 delay(10000);

}


Here is reading code:

Code:
#include <Wire.h>


void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
}

void loop()
{
  Wire.requestFrom(0x50,255);
  int x = Wire.available();
  Serial.println(Wire.available(),HEX);
  
  delay(50);
  Serial.println("Entering Loop for 2048 Bytes");
  
  for(int i = 0; i<2048;i++){
    byte rdata;
    
     if (Wire.available()){
        rdata = Wire.receive();
      }else{
        Serial.print("Breaking after : ");
        Serial.print(a);
        Serial.println(" Bytes");
        break;
      }
      Serial.print("Byte(");
      Serial.print(a);
      Serial.print(") ");
    Serial.print(i);
    Serial.print(" : ");
   Serial.println(rdata,HEX);
    
    a++;
 
}
 
}


Here is Reading code output:
Code:
Byte(0) 0 : 3A
Byte(1) 1 : 3B
Byte(2) 2 : 3C
Byte(3) 3 : 35
Byte(4) 4 : 36
Byte(5) 5 : 37
Byte(6) 6 : FF
Byte(7) 7 : FF
Byte(8) 8 : FF
Byte(9) 9 : FF
Byte(10) 10 : FF
Byte(11) 11 : FF
Byte(12) 12 : FF
Byte(13) 13 : FF
Byte(14) 14 : FF
Byte(15) 15 : FF
Byte(16) 16 : FF
Byte(17) 17 : FF
Byte(18) 18 : FF
Byte(19) 19 : FF
Byte(20) 20 : FF
Byte(21) 21 : FF
Byte(22) 22 : FF
Byte(23) 23 : FF
Byte(24) 24 : FF
Byte(25) 25 : FF
Byte(26) 26 : FF
Byte(27) 27 : FF
Byte(28) 28 : FF
Byte(29) 29 : FF
Byte(30) 30 : FF
Byte(31) 31 : FF
Breaking after : 32 Bytes
20
Entering Loop for 2048 Bytes
Byte(32) 0 : FF
Byte(33) 1 : FF
Byte(34) 2 : FF
Byte(35) 3 : FF
Byte(36) 4 : FF
Byte(37) 5 : FF
Byte(38) 6 : FF
Byte(39) 7 : FF
Byte(40) 8 : FF
Byte(41) 9 : FF
Byte(42) 10 : FF
Byte(43) 11 : FF
Byte(44) 12 : FF
Byte(45) 13 : FF
Byte(46) 14 : FF
Byte(47) 15 : FF
Byte(48) 16 : FF
Byte(49) 17 : FF
Byte(50) 18 : FF
Byte(51) 19 : FF
Byte(52) 20 : FF
Byte(53) 21 : FF
Byte(54) 22 : FF
Byte(55) 23 : FF
Byte(56) 24 : FF
Byte(57) 25 : FF
Byte(58) 26 : FF
Byte(59) 27 : FF
Byte(60) 28 : FF
Byte(61) 29 : FF
Byte(62) 30 : FF
Byte(63) 31 : FF
Breaking after : 64 Bytes
20
Entering Loop for 2048 Bytes
Byte(64) 0 : FF
Byte(65) 1 : FF
Byte(66) 2 : FF
Byte(67) 3 : FF
Byte(68) 4 : FF
Byte(69) 5 : FF
Byte(70) 6 : FF
Byte(71) 7 : FF
Byte(72) 8 : FF
Byte(73) 9 : FF
Byte(74) 10 : FF
Byte(75) 11 : FF
Byte(76) 12 : FF
Byte(77) 13 : FF
Byte(78) 14 : FF
Byte(79) 15 : FF
Byte(80) 16 : FF
Byte(81) 17 : FF
Byte(82) 18 : FF
Byte(83) 19 : FF
Byte(84) 20 : FF
Byte(85) 21 : FF
Byte(86) 22 : FF
Byte(87) 23 : FF
Byte(88) 24 : FF
Byte(89) 25 : FF
Byte(90) 26 : FF
Byte(91) 27 : FF
Byte(92) 28 : FF
Byte(93) 29 : FF
Byte(94) 30 : FF
Byte(95) 31 : FF
Breaking after : 96 Bytes
20
Entering Loop for 2048 Bytes
Byte(96) 0 : FF
Byte(97) 1 : FF
Byte(98) 2 : FF
Byte(99) 3 : FF
Byte(100) 4 : FF
Byte(101) 5 : FF
Byte(102) 6 : FF
Byte(103) 7 : FF
Byte(104) 8 : FF
Byte(105) 9 : FF
Byte(106) 10 : FF
Byte(107) 11 : FF
Byte(108) 12 : FF
Byte(109) 13 : FF
Byte(110) 14 : FF
Byte(111) 15 : FF
Byte(112) 16 : FF
Byte(113) 17 : FF
Byte(114) 18 : FF
Byte(115) 19 : FF
Byte(116) 20 : FF
Byte(117) 21 : FF
Byte(118) 22 : FF
Byte(119) 23 : FF
Byte(120) 24 : FF
Byte(121) 25 : FF
Byte(122) 26 : FF
Byte(123) 27 : FF
Byte(124) 28 : FF
Byte(125) 29 : FF
Byte(126) 30 : FF
Byte(127) 31 : FF
Breaking after : 128 Bytes
20
Entering Loop for 2048 Bytes
Byte(128) 0 : FF
Byte(129) 1 : FF
Byte(130) 2 : FF
Byte(131) 3 : FF
Byte(132) 4 : FF
Byte(133) 5 : FF
Byte(134) 6 : FF
Byte(135) 7 : FF
Byte(136) 8 : FF
Byte(137) 9 : FF
Byte(138) 10 : FF
Byte(139) 11 : FF
Byte(140) 12 : FF
Byte(141) 13 : FF
Byte(142) 14 : FF
Byte(143) 15 : FF
Byte(144) 16 : FF
Byte(145) 17 : FF
Byte(146) 18 : FF
Byte(147) 19 : FF
Byte(148) 20 : FF
Byte(149) 21 : FF
Byte(150) 22 : FF
Byte(151) 23 : FF
Byte(152) 24 : FF
Byte(153) 25 : FF
Byte(154) 26 : FF
Byte(155) 27 : FF
Byte(156) 28 : FF
Byte(157) 29 : FF
Byte(158) 30 : FF
Byte(159) 31 : FF
Breaking after : 160 Bytes
20
Entering Loop for 2048 Bytes
Byte(160) 0 : FF
Byte(161) 1 : FF
Byte(162) 2 : FF
Byte(163) 3 : FF
Byte(164) 4 : FF
Byte(165) 5 : FF
Byte(166) 6 : FF
Byte(167) 7 : FF
Byte(168) 8 : FF
Byte(169) 9 : FF
Byte(170) 10 : FF
Byte(171) 11 : FF
Byte(172) 12 : FF
Byte(173) 13 : FF
Byte(174) 14 : FF
Byte(175) 15 : FF
Byte(176) 16 : FF
Byte(177) 17 : FF
Byte(178) 18 : FF
Byte(179) 19 : FF
Byte(180) 20 : FF
Byte(181) 21 : FF
Byte(182) 22 : FF
Byte(183) 23 : FF
Byte(184) 24 : FF
Byte(185) 25 : FF
Byte(186) 26 : FF
Byte(187) 27 : FF
Byte(188) 28 : FF
Byte(189) 29 : FF
Byte(190) 30 : FF
Byte(191) 31 : FF
Breaking after : 192 Bytes
20
Entering Loop for 2048 Bytes
Byte(192) 0 : FF
Byte(193) 1 : FF
Byte(194) 2 : FF
Byte(195) 3 : FF
Byte(196) 4 : FF
Byte(197) 5 : FF
Byte(198) 6 : FF
Byte(199) 7 : FF
Byte(200) 8 : FF
Byte(201) 9 : FF
Byte(202) 10 : FF
Byte(203) 11 : FF
Byte(204) 12 : FF
Byte(205) 13 : FF
Byte(206) 14 : FF
Byte(207) 15 : FF
Byte(208) 16 : FF
Byte(209) 17 : FF
Byte(210) 18 : FF
Byte(211) 19 : FF
Byte(212) 20 : FF
Byte(213) 21 : FF
Byte(214) 22 : FF
Byte(215) 23 : FF
Byte(216) 24 : FF
Byte(217) 25 : FF
Byte(218) 26 : FF
Byte(219) 27 : FF
Byte(220) 28 : FF
Byte(221) 29 : FF
Byte(222) 30 : FF
Byte(223) 31 : FF
Breaking after : 224 Bytes
20
Entering Loop for 2048 Bytes
Byte(224) 0 : FF
Byte(225) 1 : FF
Byte(226) 2 : FF
Byte(227) 3 : FF
Byte(228) 4 : FF
Byte(229) 5 : FF
Byte(230) 6 : FF
Byte(231) 7 : FF
Byte(232) 8 : FF
Byte(233) 9 : FF
Byte(234) 10 : FF
Byte(235) 11 : FF
Byte(236) 12 : FF
Byte(237) 13 : FF
Byte(238) 14 : FF
Byte(239) 15 : FF
Byte(240) 16 : FF
Byte(241) 17 : FF
Byte(242) 18 : FF
Byte(243) 19 : FF
Byte(244) 20 : FF
Byte(245) 21 : FF
Byte(246) 22 : FF
Byte(247) 23 : FF
Byte(248) 24 : FF
Byte(249) 25 : FF
Byte(250) 26 : FF
Byte(251) 27 : FF
Byte(252) 28 : FF
Byte(253) 29 : FF
Byte(254) 30 : 1D
Byte(255) 31 : 2

Output is all supposed to be 2 not FF 1D etc only 2 but its not so this means that either my writing or reading codes are flawed.
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: I²C Memory Card Help. Cant Write more than one bit on: September 20, 2010, 01:33:06 am
I have realized that but it still wont write and read consistently. I have 1k pull-ups on the SDA and SCL lines.

13  Forum 2005-2010 (read only) / Syntax & Programs / Re: I²C Memory Card Help. Cant Write more than one bit on: September 20, 2010, 12:37:59 am
Please anyone? I have it as a smart card, so i dont have access to A0 A1 A2 so i just put them as 0. Can anyone please help me write to this card in a way that i can track?
14  Forum 2005-2010 (read only) / Syntax & Programs / I²C Memory Card Help. Cant Write more than one bit on: September 18, 2010, 02:00:02 pm
Hi all,

I have a smart card here and i can only read and write one "sector" like only the first "slot" in the i2c memory card and i can fill it with stuff like AB but that is it.

How can i get this software to allow to me write to all sectors?

My cards datasheet is : http://www.atmel.com/dyn/resources/prod_documents/doc5279.pdf

I now have this code:

Code:
#include <Wire.h>

void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
  int rdata = data;
  Wire.beginTransmission(deviceaddress);
  Wire.send((int)(eeaddress >> 8)); // MSB
  Wire.send((int)(eeaddress & 0xFF)); // LSB
  Wire.send(rdata);
  Wire.endTransmission();
}

// WARNING: address is a page address, 6-bit end will wrap around
// also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length ) {
  Wire.beginTransmission(deviceaddress);
  Wire.send((int)(eeaddresspage >> 8)); // MSB
  Wire.send((int)(eeaddresspage & 0xFF)); // LSB
  byte c;
  for ( c = 0; c < length; c++)
    Wire.send(data[c]);
  Wire.endTransmission();
}

byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
  byte rdata = 0xFF;
  Wire.beginTransmission(deviceaddress);
  Wire.send((int)(eeaddress >> 8)); // MSB
  Wire.send((int)(eeaddress & 0xFF)); // LSB
  Wire.endTransmission();
  Wire.requestFrom(deviceaddress,1);
  if (Wire.available()) rdata = Wire.receive();
  return rdata;
}

// maybe let's not read more than 30 or 32 bytes at a time!
void i2c_eeprom_read_buffer( int deviceaddress, unsigned int eeaddress, byte *buffer, int length ) {
  Wire.beginTransmission(deviceaddress);
  Wire.send((int)(eeaddress >> 8)); // MSB
  Wire.send((int)(eeaddress & 0xFF)); // LSB
  Wire.endTransmission();
  Wire.requestFrom(deviceaddress,length);
  int c = 0;
  for ( c = 0; c < length; c++ )
    if (Wire.available()) buffer[c] = Wire.receive();
}


void setup()
{
  Wire.begin();
  Serial.begin(9600);
}

void loop()
{
  i2c_eeprom_write_byte(0x50, 1, 0xaa);
  Serial.println("waiting");
  delay(1000);
 byte temp = i2c_eeprom_read_byte(0x50, 1);
  Serial.println(temp);
  delay(2000);
  
}

Ive tried change the :
Code:
i2c_eeprom_write_byte(0x50, 1, 0xaa);
to :
Code:
i2c_eeprom_write_byte(0x50, 2, 0xaa);
but it wont write to the second bit!! It writes well to the first but now the second or third. How can i go about to make it right beyond the 1st bit. Also was does the 0x50 represent?

Thanks,
Spooky
15  Forum 2005-2010 (read only) / Development / Re: arduino with internal oscillator on 1Mhz on: October 02, 2009, 04:27:13 am
Why reprogram the arduino when you can just buy a crystal for 2 bucks
Pages: [1] 2