i use 24LC512 as I2C1 and MMCcard as SPI1 on same pins(PORTC2,3,4 and 5. 3-4 pins shared for I2c1 and SPI1) on 18F46K22.
i must transfer to MMCcard(fat16) from 25LC512's data.
But not working MMCCard.
And i try I2C2 (not I2C1) with other pins (D0 and D1 pin), but it's not working 24LC512. is I2C1 different from I2C2 _?
part of code is this:
Code: Select all
Procedure MMCyeKaydet();
var
DosyaNo,VeriX:integer;
Label DosyaVarmi;
begin
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
// use fat16 quick format instead of init routine if a formatting is needed
if Mmc_Fat_Init() = 0 then
begin
// reinitialize spi at higher speed
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
DosyaVarmi:
DosyaAdi:='XF'+num2str(DosyaNo)+'.DAT';
if Mmc_Fat_Exists(DosyaAdi) then
begin
inc(DosyaNo);
Goto DosyaVarmi;
Exit;
end;
Mmc_Fat_Assign(DosyaAdi, 0);
Mmc_Fat_Append();
VeriX:=0;
While VeriX< EpromVeriBoyut(0) do
begin
I2C1_Start(); // issue I2C start signal
I2C1_Wr(0xA0); // send byte via I2C (device address + W)
I2C1_Wr(Hi(VeriX)); // send byte (address of EEPROM location)
I2C1_Wr(Lo(VeriX)); // send byte (address of EEPROM location)
I2C1_Repeated_Start();
I2C1_Wr(0xA1);
satir:=num2str(I2C1_Rd(0)+I2C1_Rd(1)) + ' ' + num2str(I2C1_Rd(2)+I2C1_Rd(3)) + ' ' +num2str(I2C1_Rd(4)+I2C1_Rd(5));
I2C1_Stop(); // issue I2C stop signal: //
while NOT I2C1_Is_Idle do nop;
inc(VeriX);
satir[15] := 13; // CR
satir[16] := 10; // LF
Mmc_Fat_Write(Satir, 16); // Write data to assigned file
end;
end
else
begin
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,'MMC FAT16 ERROR');
Delay_ms(1000);
Reset;
end;
end;