View previous topic :: View next topic |
Author |
Message |
applecon2000
Joined: 29 Jul 2007 Posts: 31 Location: UK
|
ask for help |
Posted: Fri Aug 17, 2007 11:28 am |
|
|
Dear all,
after building RS232 interface in my LCD module, I wanna build I2C and SPI interfaces into it as well, is there any friend who can give me the suggestion about the code for those two interfaces.
As the codes I writing for I2C and SPI:
Code: | #USE RS232(BAUD=9600,XMIT=PIN_C6,RCV=PIN_C7)
#USE I2C(slave, sda=PIN_C4, scl=PIN_C3, address=0xA0)
...
while(1)
{
while(!i2c_poll());
lcd_putc("\f I2C data: \n");
value3=i2c_read();
lcd_putc(value3);
} //end while of I2C
while(1)
{
output_low(PIN_A5);
while(!spi_data_is_in() && input(PIN_A5));
if (spi_data_is_in())
value3=spi_read();
lcd_putc(value3);
} //end while of SPI |
But it seems not work well. My LCD module would be treated as a slave mode, just being used to receive data from other hardware.
Thanks for your help indeed. _________________ Enjoy our EEE |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Aug 17, 2007 11:45 am |
|
|
You should stop posting questions in the Code Library. Post them
only in this forum (The General Discussion forum). On the main forum
index page, Darren has posted a warning about this:
Quote: |
Code Library
Post and share your WORKING libraries and examples for other users
to use. This is -NOT- the forum to be asking for help. |
Also, don't do double posts. Don't post the same thing two or more times.
Here is the link for the main CCS forum (the one you're in now).
Bookmark this link, and delete the link that you have to the Code Library.
http://www.ccsinfo.com/forum/viewforum.php?f=1 |
|
|
applecon2000
Joined: 29 Jul 2007 Posts: 31 Location: UK
|
dear sir |
Posted: Fri Aug 17, 2007 5:35 pm |
|
|
As a frashman using this system, I am not really familar with your rules.
Sorry to bring you so many troubles. _________________ Enjoy our EEE |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Aug 17, 2007 6:04 pm |
|
|
I don't understand your question. Do you want to connect all of RS232, SPI and I2C at the same time?
For an I2C master the functions can be emulated by software but for a slave you always have to select the SSP hardware unit of the PIC.
The i2c_poll() function only works in combination with the SSP hardware unit. By default the #use I2C directive generates a software I2C driver. Change to Code: | #USE I2C(slave, sda=PIN_C4, scl=PIN_C3, address=0xA0, FORCE_HW) |
In your SPI code you have: Code: | output_low(PIN_A5);
while(!spi_data_is_in() && input(PIN_A5)); | How is your hardware connected? Now you are using PIN_A5 for both input _and_ output. This looks like a bug.
Where is your setup_spi() call? |
|
|
applecon2000
Joined: 29 Jul 2007 Posts: 31 Location: UK
|
Thanks first but...... |
Posted: Fri Aug 17, 2007 6:35 pm |
|
|
My project was to use PIC16F876 to drive a 16x2 LCD module. SPI and I2C were two interfaces needed to build in it.
As treating my LCD module as a slave item, I wanna simulate my design in ISIS, my RS232 was working well, but I can't simulate those two successfully.
For SPI PIN_A5 being a Selecting signal with the low level to startup data transmitting.
Could you please show me one simple program which driving SPI and I2C working in microchip?
I am so glad to receive your reply, anyway, sorry to bring you so many troubles, what I can do now just give you my acknowledgement.
Best regards. _________________ Enjoy our EEE |
|
|
|