CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

18F2550 I2c Software

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
vtrx



Joined: 11 Oct 2017
Posts: 141

View user's profile Send private message

18F2550 I2c Software
PostPosted: Tue Sep 14, 2021 4:50 pm     Reply with quote

I need to use a 24C08 memory with the 18F2550, but using software routines.
I use native SPI for another circuit.
Using the described methods, I can't get results in the simulation.
Is the described procedure correct?

Code:
#use I2C(sda=PIN_A1, scl=PIN_A0, FAST=100000)
...
void ext_24c08_write(unsigned int8 address,data)
{
  i2c_start();                         
  i2c_write(WRITE_ADDR);                   
  i2c_write(address);                   
  i2c_write(data);                 
  i2c_stop();                           
}

int8 ext_24c08_read(unsigned int8 address)
{
int8 result;

   i2c_start();                         
   i2c_write(WRITE_ADDR);                   
   i2c_write(address);                     
   i2c_start();                         
   i2c_write(READ_ADDR);                     
   result = i2c_read(1);
   i2c_stop();
   return(result);
}
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Sep 14, 2021 5:59 pm     Reply with quote

simulation' ?
What are you using as a 'simulator' ??
vtrx



Joined: 11 Oct 2017
Posts: 141

View user's profile Send private message

PostPosted: Tue Sep 14, 2021 7:31 pm     Reply with quote

Before losing more hair, I simulated with Proteus.
Are the codes correct?
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Sep 14, 2021 7:47 pm     Reply with quote

sorry, but I don't use Proteus. It's well know to not work 100% as a PIC simulator.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 14, 2021 8:04 pm     Reply with quote

Why don't you use the 2408.c file provided by CCS in the Drivers folder ?
It's significantly different than what you posted. You should try it.
vtrx



Joined: 11 Oct 2017
Posts: 141

View user's profile Send private message

PostPosted: Wed Sep 15, 2021 9:08 am     Reply with quote

PCM programmer wrote:
Why don't you use the 2408.c file provided by CCS in the Drivers folder ?
It's significantly different than what you posted. You should try it.


Thanks.
I'm going to use this method, anyway the problem was in emulation.
Every time I want to use a communication, which the microcontroller has implemented by hardware, and I want to use it by software, I just need to choose non-standard pins?
dyeatman



Joined: 06 Sep 2003
Posts: 1910
Location: Norman, OK

View user's profile Send private message

PostPosted: Wed Sep 15, 2021 9:14 am     Reply with quote

You can also use the FORCE_SW switch under I2C.
See the #use I2C section in the manual
_________________
Google and Forum Search are some of your best tools!!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Sep 15, 2021 9:24 am     Reply with quote

Honestly I'd suspect the 'simulation'. It probably cannot actually handle
interpreting software I2C.

The reason the standard driver is different, is that the address for the
2408, is actually a 10bit value, and the extra 2 bits have to be masked
into the device address sent. However omitting these (provided your
value for WRITE_ADDR, and READ_ADDR, have sensible settings for these,
that match), should not matter.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 15, 2021 9:55 am     Reply with quote

Quote:
int8 ext_24c08_read(unsigned int8 address)
{
int8 result;

i2c_start();
i2c_write(WRITE_ADDR);
i2c_write(address);
i2c_start();
i2c_write(READ_ADDR);
result = i2c_read(1);
i2c_stop();
return(result);
}

Also, your code above is incorrect. The last i2c_read() should have
a parameter of 0. Look at the CCS code. They have a 0. This is part
of the i2c spec.
vtrx



Joined: 11 Oct 2017
Posts: 141

View user's profile Send private message

PostPosted: Wed Sep 15, 2021 3:00 pm     Reply with quote

I'm using 2408.c (write_ext_eeprom(x,x)/read_ext_eeprom(x)).
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Thu Sep 16, 2021 3:53 am     Reply with quote

PCM is pointing out why your original code would not work.
Learn from him for any future code you write.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group