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 CCS Technical Support

using sda and scl pins in parallel with using i2c functions

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



Joined: 09 Jul 2009
Posts: 11

View user's profile Send private message

using sda and scl pins in parallel with using i2c functions
PostPosted: Mon Jul 20, 2009 10:26 am     Reply with quote

Hi all,

I am pleased to say that with help from the forum I can now successfully do read and write accesses using my I2c software master implemented on a pic16f960.

My next task is to talk to a very small lcd display via the same I2c pins (sda and scl). The serial protocl used by this display actually isnt I2c at all. The display uses a third chip select pin (active low) to select when to write to the device. Basically the whole transaction is 16 bits in total. The first 8 bits are the register address and the read/write bit. The last 8 bits is the data for the particular register.

I am currently trying to figure out how to drive the SDA and SCL pins on my own while still using the CCS I2C functions to talk to the I2C slave.
I thought I would just have to set the tris bits appropriately for the port and write to the port register. However, when I drive a zero on the SDA and SCL pins the output gets pulled high. I do have internal pull ups enabled (for ports a and b) via bit 7 of the options register. However, I thought I would be able to drive the SDA and SCL pins low when necessary.

If anyone has any suggestions it would be much appreciated. I have left my settings below.

Cheers
Mike

Code:
#include <16F690.h>
#device adc=8

#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES PUT                      //No Power Up Timer
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOCPD                    //No EE protection
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT

#use delay(internal=4M)
#use i2c(Master,Slow,sda=PIN_B4,scl=PIN_B6,FORCE_SW)
#use fixed_io(c_outputs=PIN_C6, PIN_C7)
#use fixed_io(b_outputs=PIN_B5)

#include "C:\mydocs\picfware\i2c_master_trial\main.h"

#define set_options(value)   {#ASM         \
                              MOVLW  value \
                              OPTION       \
                              #ENDASM}

void main()
{
   set_options(0x7f); // enable weak pull ups for ports A and B
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
   setup_oscillator(OSC_4MHZ);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 20, 2009 10:50 am     Reply with quote

Quote:

My next task is to talk to a very small lcd display via the same I2c pins
(sda and scl). The serial protocl used by this display actually isnt I2c at
all. The display uses a third chip select pin (active low) to select when to
write to the device

Post the manufacturer and part number of the lcd. Post a link to the
data sheet for it.
mikem



Joined: 09 Jul 2009
Posts: 11

View user's profile Send private message

PostPosted: Tue Jul 21, 2009 2:07 am     Reply with quote

Hi PCM programmer,

unfortunately I cannot find the display datasheet on the web. Its from AUO and they seem to keep there datasheets under lock and key.

Basically my problem is trying to take control of the sda and scl pins on the pic16f690 because I am using the ccs routines to create a software master.

Cheers
Mike
mikem



Joined: 09 Jul 2009
Posts: 11

View user's profile Send private message

PostPosted: Tue Jul 21, 2009 2:27 am     Reply with quote

Hi again PCM programmer,

I found a link to a AUO datasheet with the same serial control interface that the display I am using.

http://www.gaw.ru/pdf/lcd/lcm/auo/A030DL01.pdf (pages 18 and 19)

I don't think you need to worry about the display to much. I think my problem is that I am not setting up the pic properly to drive the sda and scl pins as I want.

Cheers
Mike
mikem



Joined: 09 Jul 2009
Posts: 11

View user's profile Send private message

PostPosted: Tue Jul 21, 2009 4:34 am     Reply with quote

Hi,

so I was able to sort out my problem. After looking at assmebler code generated I noticed that the tris bits for port B were never getting set while using output_b to drive the sda and scl pins. I think this is because the compiler creates some kind of bit mask because I used the #use fixed_io and only specified one pin of the port b pins (sda and scl were not specified).

I have decided to use #use fast_io and just specify the tris value at the beginning of my code. Then when I need to drive the sda and scl pins outside of the ccs i2c functions I can set the port b tris register accordingly and then use the output_b to apply the output value.

Code:
   set_tris_b(0x8f);
   output_b(0x8f);
   delay_ms(1);
   output_b(0xff);
   set_tris_b(0xdf);


I have tested my theory and it works. Also the ccs I2c functions take care of the relevant tris setting eventhough #use fast_io is specified.

Cheers
Mike
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