I2C1 and SPI1 same pin, is possible_?

General discussion on mikroPascal PRO for PIC.
Post Reply
Author
Message
poke53280
Posts: 5
Joined: 27 Sep 2014 10:32

I2C1 and SPI1 same pin, is possible_?

#1 Post by poke53280 » 25 Mar 2015 17:21

Hi,
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;
and circuit is this:
Noname.png
Noname.png (87.59 KiB) Viewed 1649 times
Thanks.

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: I2C1 and SPI1 same pin, is possible_?

#2 Post by Aleksandar.Mitrovic » 26 Mar 2015 17:29

Hi,

As I can see from the datasheet for PIC18F46K22 you have 2 I2C's:
I2C1 on pins:
- RC3 (SCL1)
- RC4 (SDA1)
I2C2 on pins:
- RD0 (SLC2)
- RD1 (SDA2)

Yes I2C1 is different from I2C2.

Also Proteus is really not supported mikroElektronika certified environment on which your test can be performed. So, this is out of our support scope.
Thank you for your understanding.

Best regards,
Aleksandar

Post Reply

Return to “mikroPascal PRO for PIC General”