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

Problem with i2c bus

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



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

Problem with i2c bus
PostPosted: Mon Feb 13, 2006 4:24 pm     Reply with quote

None of i2c devices on the i2c bus did not function anymore.
I have an onboard saa1064 and an extern pcf8577

Whats can cause the problem?

I have remove the uC for a new one, no change
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

PostPosted: Mon Feb 13, 2006 5:11 pm     Reply with quote

code?
schematic?
board matches schematic?
parts match BOM? (check i2c pullups)

behaviour before problem started?
changes that were made?
behaviour after problem was noticed?

what troubleshooting have you tried?
what were the results?

jds-pic
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Mon Feb 13, 2006 6:04 pm     Reply with quote

That's a bit like me saying:

I'm trying to read the temperature from a sensor but it doesn't work. What's wrong with it?

You need to give a lot more information before we can even begin to assume what's going on.
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Mon Feb 13, 2006 6:33 pm     Reply with quote

You probably got a bad i2c slave that is holding the SCL line hostage! Try desoldering it and putting a new one back in.
The Puma



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Feb 14, 2006 12:02 pm     Reply with quote

This is my board
http://www.embedded-channel.de/products/uniboard/product.htm

I have made no changes to it
The board is the same then the times it worked

The SAA1064 has i2c address 0x70


#include <18F4620.h>
#use delay(clock=2000000)
#fuses HS,NOWDT,NOBROWNOUT,NOPUT,NOLVP,DEBUG,NOSTVREN,NOPROTECT
#use i2c(master,sda=PIN_C4,scl=PIN_C3,FORCE_HW)

#include <saa1064.h>

int16 count = 0;

void main(void)
{
// Display 'On' on display with SAA1064 ADR pin tied to Vee
send_saa1064_msg(LED_ADDR0,LED_CONTROL,on_);
delay_ms(1000);
send_saa1064_msg(LED_ADDR0,LED_CONTROL,blank_);
delay_ms(300);

while(1)
{
send_saa1064_num(LED_ADDR0,LED_CONTROL,count);
if(++count == 10000) count = 0;
delay_ms(100);
}
}

// Driver for SAA1064 i2c to multiplexed four-digit, seven-segment led display

// SAA1064 write addresses set by connecting pin1 (ADR) to different voltages
#define LED_ADDR0 0x70 // ADR to Vee
#define LED_ADDR1 0x72 // ADR to 3/8 Vcc
#define LED_ADDR2 0x74 // ADR to 5/8 Vcc
#define LED_ADDR3 0x76 // ADR to Vcc

// Control bits
// C0 = 0 = static mode C0 = 1 dynamic mode
// C1 = 0/1 digits 1 and 3 are blanked/not blanked
// C2 = 0/1 digits 2 and 4 are blanked/not blanked
// C3 = 1 all segments outputs turned on for segment test
// C4 = 1 adds 3ma to segment output
// C5 = 1 adds 6ma to segment output
// C6 = 1 adds 12ma to segment output
// C7 n/a

#define LED_CONTROL 0x27 //Dynamic mode 6mA

// Segment table (In hex: d.p.=80,g=40,f=20,e=10,d=08,c=04,b=02,a=01)
byte const seg_table[10]=
{0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; // 0,1,2,3,4,5,6,7,8,9

// Some non-numeric characters
//0x00,0x77,0x7C,0x39,0x5E,0x79,0x71,0x36,0x04,0x38, // blank,A,b,C,d,E,F,H,i,L
//0x54,0x5C,0x73,0x50,0x6B,0x1C,0x6E,0x40,0x08 // n,o,p,r,S,u,y,-,_


// Message examples
byte const blank[4] = {0x00,0x00,0x00,0x00};// Blank display
byte const err[4] = {0x00,0x79,0x50,0x50}; // Err
byte const on[4] = {0x00,0x00,0x3F,0x54}; // On
byte const off[4] = {0x00,0x3F,0x71,0x71}; // OFF

enum {blank_,err_,on_,off_};

//--------------------------------------------------------------------------
// Sends number to four-digit led display via SAA1064 (0 to 9999)
void send_saa1064_num(int8 addr,int8 control,int16 num)
{
int8 j; // Digit index
int8 led_data[4]; // Ram array for segment data
int16 temp16;

// Get led segments for all four digits. Don't need to divide to get units.
temp16 = num;
j = 0;

while (j <= 3)
{
if (j != 0) temp16 /= 10;
led_data[j] = seg_table[temp16 %10];
j++;
}

// Do leading zero blanking
if (num<1000) led_data[3] = 0x00;
if (num<100) led_data[2] = 0x00;
if (num<10) led_data[1] = 0x00;

// Add decimal point if required
//led_data[2] |= 0x80;

// Send led segments
i2c_start();
i2c_write(addr); // Send SAA1064 address
i2c_write(0x00); // Send instruction byte. Zero is control reg.
i2c_write(control); // Send control byte

// Auto increment applies for digit data. Have to send out digits in reverse
// because most significant digit is 1st digit.
for (j=4;j>=1;j--)
i2c_write(led_data[j-1] & 0xff);

i2c_stop();
}
//---------------------------------------------------------------------------
//Sends message to led display via SAA1064
void send_saa1064_msg(int8 addr,int8 control,int8 msg)
{
int8 j;
int8 led_data[4]; // Ram array for segments

// Get segments for message.
switch (msg)
{
case blank_:
for(j=0;j<=3;j++)
led_data[j] = blank[j];
break;

case err_:
for(j=0;j<=3;j++)
led_data[j] = err[j];
break;

case on_:
for(j=0;j<=3;j++)
led_data[j] = on[j];
break;

case off_:
for(j=0;j<=3;j++)
led_data[j] = off[j];
break;

default:
for(j=0;j<=3;j++)
led_data[j] = blank[j];
break;
}

// Send led segments
i2c_start();
i2c_write(addr); // Send SAA1064 address
i2c_write(0x00); // Send instruction byte. Zero is control reg.
i2c_write(control); // Send control byte

for (j=0;j<=3;j++)
i2c_write(led_data[j]);

i2c_stop();
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 14, 2006 1:25 pm     Reply with quote

Look closely at the first few lines of your program. There is a problem.
Does the value that you have in one of the lines below match
your hardware ? I doubt it. As I've said, details are important.
Code:
#include <18F4620.h>
#use delay(clock=2000000)
#fuses HS,NOWDT,NOBROWNOUT,NOPUT,NOLVP,DEBUG,NOSTVREN,NOPROTECT
The Puma



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Feb 14, 2006 1:39 pm     Reply with quote

i have this driver for the SPI port and this works

#include <18F4620.h>
#use delay(clock=2000000)
#fuses HS,NOWDT,NOBROWNOUT,NOPUT,NOLVP,DEBUG,NOSTVREN,NOPROTECT

#include <max7221.h>

int32 j;

void main() {

setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16);

max7221_init();
max7221_blank_display();

for(j=0;j<10000;j++) {
max7221_write_num(j);
delay_ms(500);
}
}

////////////////////////////////////////////////////////////////////////////
//// MAX7221.H ////
//// Driver for Serially Interfaced, 8-Digit, LED Display ////
//// ////
//// max7221_init() Must be called before any other function. ////
//// ////
//// max7221_put(addr,data) Send data to LED-display ////
//// ////
//// max7221_write_num(num) Send num to LED-display ////
//// ////
//// max7221_blank_display() Blank LED-display ////
//// ////
////////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,1997 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS C ////
//// compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, reproduction ////
//// or distribution is permitted without written permission. ////
//// Derivative programs created using this software in object code ////
//// form are not restricted in any way. ////
////////////////////////////////////////////////////////////////////////////

#ifndef MAX7221_CS

#define MAX7221_CS PIN_C0
#define MAX7221_CLK PIN_C3
#define MAX7221_DOUT PIN_C4
#define MAX7221_DIN PIN_C5

#endif

// Register address map
#define NO_OP 0x00 // Used when cascading max7221s
#define DIGIT_0 0x01 // Digit 0 register
#define DIGIT_1 0x02 // Digit 1 register
#define DIGIT_2 0x03 // Digit 2 register
#define DIGIT_3 0x04 // Digit 3 register
#define DIGIT_4 0x05 // Digit 4 register
#define DIGIT_5 0x06 // Digit 5 register
#define DIGIT_6 0x07 // Digit 6 register
#define DIGIT_7 0x08 // Digit 7 register
#define DECODE_MODE 0x09 // Decode mode register
#define INTENSITY 0x0A // Intensity register
#define SCAN_LIMIT 0x0B // Scan-limit register
#define SHUT_DOWN 0x0C // Shutdown register
#define DISPLAY_TEST 0x0F // Display-test register

// Shutdown register
#define SHUTDOWN_MODE 0x00 // Shutdown mode
#define NORMAL_MODE 0x01 // Normal mode

// Decode-mode register
#define NO_DECODE_DIGITS_7_0 0x01 // No decode for digits 7-0
#define CODE_B_DECODE_DIGIT_0 0x02 // Code B decode for digit 0
#define CODE_B_DECODE_DIGITS_3_0 0x0F // Code B decode for digits 3-0
#define CODE_B_DECODE_DIGITS_7_0 0xFF // Code B decode for digits 7-0

// Code B font
#define SEGMENT_CHAR_0 0x00 // 0
#define SEGMENT_CHAR_1 0x01 // 1
#define SEGMENT_CHAR_2 0x02 // 2
#define SEGMENT_CHAR_3 0x03 // 3
#define SEGMENT_CHAR_4 0x04 // 4
#define SEGMENT_CHAR_5 0x05 // 5
#define SEGMENT_CHAR_6 0x06 // 6
#define SEGMENT_CHAR_7 0x07 // 7
#define SEGMENT_CHAR_8 0x08 // 8
#define SEGMENT_CHAR_9 0x09 // 9
#define SEGMENT_CHAR_- 0x0A // -
#define SEGMENT_CHAR_E 0x0B // E
#define SEGMENT_CHAR_H 0x0C // H
#define SEGMENT_CHAR_L 0x0D // L
#define SEGMENT_CHAR_P 0x0E // P
#define SEGMENT_CHAR_BLANK 0x0F // BLANK
#define SEGMENT_CHAR_DP 0x80 // DP

// Intensity register
#define DUTY_CYCLE_1 0x00 // Intensity min
#define DUTY_CYCLE_2 0x01
#define DUTY_CYCLE_3 0x02
#define DUTY_CYCLE_4 0x03
#define DUTY_CYCLE_5 0x04
#define DUTY_CYCLE_6 0x05
#define DUTY_CYCLE_7 0x06
#define DUTY_CYCLE_8 0x07
#define DUTY_CYCLE_9 0x08
#define DUTY_CYCLE_10 0x09
#define DUTY_CYCLE_11 0x0A
#define DUTY_CYCLE_12 0x0B
#define DUTY_CYCLE_13 0x0C
#define DUTY_CYCLE_14 0x0D
#define DUTY_CYCLE_15 0x0E
#define DUTY_CYCLE_16 0x0F // Intensity full

// Scan-limit register
#define DISPLAY_DIGIT_0 0x00 // Display digit 0
#define DISPLAY_DIGITS_01 0x01 // Display digits 0 & 1
#define DISPLAY_DIGITS_012 0x02 // Display digits 0 1 2
#define DISPLAY_DIGITS_0123 0x03 // Display digits 0 1 2 3
#define DISPLAY_DIGITS_01234 0x04 // Display digits 0 1 2 3 4
#define DISPLAY_DIGITS_012345 0x05 // Display digits 0 1 2 3 4 5
#define DISPLAY_DIGITS_0123456 0x06 // Display digits 0 1 2 3 4 5 6
#define DISPLAY_DIGITS_01234567 0x07 // Display digits 0 1 2 3 4 5 6 7

// Display-test register
#define NORMAL_OPERATION 0x00 // Normal operation
#define DISPLAY_TEST_MODE 0x01 // Display-test mode, all leds on

void max7221_put(int addr, int data) {
output_low(MAX7221_CS);
spi_write(addr);
spi_write(data);
output_high(MAX7221_CS);
}

void max7221_write_num(int32 num) {
int1 leading=true;
int8 led_data[8];
int8 j;
int32 temp32;

for(j=0;j<7;j++) {
temp32=num/10;
led_data[j]=num-(temp32*10);
num=temp32;
}
led_data[7]=num;

for(j=7;j>0;j--) {
if (leading && led_data[j]==0)
led_data[j]=SEGMENT_CHAR_BLANK;
else
leading=false;
}
for(j=DIGIT_0;j<=DIGIT_7;j++)
max7221_put(j,led_data[j-1]);
}

void max7221_blank_display() {
int8 j;

for(j=DIGIT_0;j<=DIGIT_7;j++)
max7221_put(j,SEGMENT_CHAR_BLANK);
}

void max7221_init() {
max7221_put(DECODE_MODE,CODE_B_DECODE_DIGITS_7_0);
max7221_put(SCAN_LIMIT,DISPLAY_DIGITS_01234567);
max7221_put(SHUT_DOWN,NORMAL_MODE);
max7221_put(INTENSITY,DUTY_CYCLE_8);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 14, 2006 2:06 pm     Reply with quote

Posting tons of code does not solve the problem.
Analysis and an eye for detail solves problems.
I'll narrow it down further.
Does the line shown in bold match your hardware ?
Maybe it does, but I doubt it.
Quote:

#include <18F4620.h>
#use delay(clock=2000000)
#fuses HS,NOWDT,NOBROWNOUT,NOPUT,NOLVP,DEBUG,NOSTVREN,NOPROTECT
The Puma



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Feb 14, 2006 2:18 pm     Reply with quote

yep the crystal is 20 Mhz

Thx PCM Programmer, i saw the problem
#use delay(clock=2000000)

This must be 20000000 Embarassed Embarassed Embarassed Embarassed
Storic



Joined: 03 Dec 2005
Posts: 182
Location: Australia SA

View user's profile Send private message Send e-mail

PostPosted: Tue Feb 14, 2006 3:21 pm     Reply with quote

My hat of to you PCM programmer, you coach a solution Idea rather that show the answer. Wink even I had learnt somthing. Rolling Eyes

Andrew
_________________
What has been learnt if you make the same mistake? Wink
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