|
|
View previous topic :: View next topic |
Author |
Message |
Prada
Joined: 22 Dec 2011 Posts: 3
|
I2C Problem in pic24FJ128GA010 |
Posted: Thu Dec 22, 2011 5:54 am |
|
|
Hi
I am currently developing a semaphore system, based on pic24fj128ga010, everything is fine except the I2C communications:
The sda & scl pins are always high...
The code is attached, if anyone know the cause I was grateful:)
Code: |
#include <24FJ128GA010.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
//#FUSES ICSP1 //ICD uses PGC1/PGD1 pins
#FUSES WINDIS //Watch Dog Timer in non-Window mode
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES PR //Primary Oscillator
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOOSCIO //OSC2 is clock output
#FUSES HS //External clock with CLKOUT
//#use fast_io(A)
#use fast_io(E)
#use fast_io(C)
#use delay(clock=32000000)
#use i2c(Master,sda=PIN_A3,scl=PIN_A2)
#include <max7312.c>
(......)
|
max7312.c
Code: |
#ifndef MAX7312_DATA
#define MAX7312_DATA PIN_A3
#define MAX7312_CLK PIN_A2
#endif
#use i2c(Master,sda=PIN_A3,scl=PIN_A2)
//prototypes
int8 max7312_read(int8 device, int8 address); //reads 7312 control register
void max7312_write(int8 device, int8 address, int8 data); //writes 7312 control register
(......)
|
Thank you for listening and if you know the solution ;) |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Thu Dec 22, 2011 7:01 am |
|
|
Do you have the correct pullup resistors on the I2C lines for your speed,PCB layout,etc.?
Have you tried another I2C device(say an RTC like the DS1307 )?
Only code snippets are shown, we'll need to see a small,compileable program that fails to offer more help. |
|
|
Prada
Joined: 22 Dec 2011 Posts: 3
|
I2C problem pic24fj128ga010 |
Posted: Thu Dec 22, 2011 7:57 am |
|
|
Thanks for the reply,
I have use 4.7k pullup resistors.
I've done the scan with the oscilloscope, and there is no clock or data.
following is a small program to compile.
Code: |
//Main.c
#include <24FJ128GA010.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
//#FUSES ICSP1 //ICD uses PGC1/PGD1 pins
#FUSES WINDIS //Watch Dog Timer in non-Window mode
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES PR //Primary Oscillator
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOOSCIO //OSC2 is clock output
#FUSES HS //External clock with CLKOUT
//#use fast_io(A)
#use fast_io(E)
#use fast_io(C)
#use delay(clock=32000000)
//#use i2c(MASTER, sda=PIN_G3, scl=PIN_G2, Fast, Force_sw)
#word AD1PCFG=0xffff
#use i2c(Master,sda=PIN_A3,scl=PIN_A2)
#include <max7312.c>
int1 RADAR1,RADAR2,PEAO;
void main(void) {
delay_ms(1000);
while(1){
output_high(PIN_A4);
delay_ms(1000);
}
delay_ms(1000);
delay_ms(1000);
max7312_init_output(0x46) ;
delay_ms(500);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
PEAO=0;
RADAR1=0;
RADAR2=0;
while(true)
{
max7312_write(0x46,0x02,0b01001100); //1ª fase
max7312_write(0x44,0x02,0b00000010);
max7312_write(0x46,0x02,0b01001010);//2ª fase
max7312_write(0x44,0x02,0b00000010);
max7312_write(0x46,0x02,0b10100001); //3ª fase
max7312_write(0x44,0x02,0b00000001);
max7312_write(0x46,0x02,0b10010001); //4ª fase
max7312_write(0x44,0x02,0b00000001);
}
}
|
Code: |
//max7312.c
#ifndef MAX7312_DATA
#define MAX7312_DATA PIN_A3
#define MAX7312_CLK PIN_A2
#endif
#use i2c(Master,sda=PIN_A3,scl=PIN_A2)
//prototypes
int8 max7312_read(int8 device, int8 address); //reads 7312 control register
void max7312_write(int8 device, int8 address, int8 data); //writes 7312 control register
void max7312_init_output(int8 device) { //Alterei esta função
output_float(MAX7312_CLK);
output_float(MAX7312_DATA);
max7312_write(device,0x06,0x00); //configura porto 1 como saída
max7312_write(device,0x02,0x00); //Coloca o porto 1 como saída(Mudar para 0x00 onde está o 0xFF)
}
void max7312_init_input(int8 device) { //Alterei esta função
output_float(MAX7312_CLK);
output_float(MAX7312_DATA);
max7312_write(device,0x06,0x11); //configura porto 1 como entrada
}
int8 max7312_read(int8 device, int8 commandByte) {
BYTE data;
i2c_start();
i2c_write(device); //endereço do escravo
i2c_write(commandByte); //commando de entrada
i2c_start();
i2c_write(commandByte | 1);//escreve endereço com read=1
data=i2c_read(0); //sem ack pq vai parar a seguir
i2c_stop();
return(data);
}
void max7312_write(int8 device, int8 address, int8 data) {
i2c_start();
i2c_write(device);
i2c_write(address);
i2c_write(data);
i2c_stop();
} |
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Dec 22, 2011 5:09 pm |
|
|
The shown code executes 2 lines continuously, but no I2C actions.
Code: | while(1){
output_high(PIN_A4);
delay_ms(1000);
} |
|
|
|
Prada
Joined: 22 Dec 2011 Posts: 3
|
I2C problem pic24fj128ga010 |
Posted: Fri Dec 23, 2011 3:53 am |
|
|
It works
I was so focused on the I2C set, which I did not notice this error in the program
Thanks for the help |
|
|
|
|
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
|