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

Big error in 12c (HELP URGENT)

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



Joined: 27 Mar 2010
Posts: 167

View user's profile Send private message

Big error in 12c (HELP URGENT)
PostPosted: Tue Jun 23, 2015 6:27 pm     Reply with quote

I have a problem I have never seen.
I made a plate with 3 peripheral devices connected in communication i2c.
But I'm not getting to use them!

These devices are:
DS 1307
MCP 3424
24LC1025
I'm using pullup of 4.7k
I'm using a pic: 18LF2685
I am using ccs in version: 5,008

In the DS1307 I get an incorrect date, is not so and never changes:
00/02/03
0:00:00

MCP-3424 readings are incorrect, arrive very small and incorrect values even changing configurations.

In 24LC1025 does not respond to my command.

I do not understand what happens, because there was already simulated in Proteus and worked properly!

Already used two different plates to see if the problem was not the board, the two work the same.
I do not know what to do!

It could be the resistors pullup?
FUSES?
COMPILER??

I checked and the call is correct.
The code I'm testing is very simple and has no complications, see below.

Can anyone help me?
already I do not know what to do ...

Code:

#include "18LF2685.h"
#device ADC=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES BBSIZ1K                  //1K words Boot Block size
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PROTECT                  //Code protected from reads

#use delay(crystal=20000000)
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=Modem)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)


#include "ds1307.c"
#include "mcp342X.c"
#include "241025.c"
#include "STRING.h"

//DEFINES
#define regulador_modem PIN_C1
#define WATCHDOG PIN_B5
#define CONFIGURA PIN_A5
#Define Buffer_size 100
//VARIAVEIS CONFIG

//LEITURAS
float analogica_1;
float analogica_2;
float analogica_3;
float analogica_4;
int32 hidrometro_1;
int32 hidrometro_2;
int32 hidrometro_3;
//VARIAVEIS RELOGIO
   unsigned int8 dia=0;
   unsigned int8 mes=0;
   unsigned int8 ano=0;
   unsigned int8 hora=0;
   unsigned int8 min=0;
   unsigned int8 seg=0;
int set_dia;                        //variaveis de SET   
int set_mes;                        //essas variaveis vao ser atribuidas pelo modem       
int set_ano;
int set_hora;
int set_min;
int set_seg;
int1 LED=1;
int1 Ativa_Interrupcao_RDA;
unsigned int16 J=0;
unsigned int16 cont_serial=0;
unsigned int32 tempo=0;
char dado_recebido_modem[Buffer_size];
BYTE _dia;
BYTE _mes;
BYTE _ano;
BYTE _dow;
BYTE _hora;
BYTE _min;
BYTE _seg;

void main()
{
   setup_adc_ports(AN0_TO_AN3);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32);      //420 ms overflow


   enable_interrupts(INT_RTCC);
   enable_interrupts(INT_EXT);
   enable_interrupts(INT_EXT1);
   enable_interrupts(INT_EXT2);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   
   output_high(regulador_modem);
   adc_init();
   ds1307_init();
   init_ext_eeprom();
   
   fprintf(Modem, "Inicio:\r\n");
   ds1307_set_date_time(16,06,2015,0,20,48,00);
   while(TRUE)
   {
   int a,b;
   
      While(1){
   
    write_ext_eeprom(a,10);
    b = read_ext_eeprom(10);
    Fprintf(Modem, "\r\n %d",b);
    a++;
    delay_ms(1000);
   }
   
   
   

      /*
      ds1307_get_date(&_dia,&_mes,&_ano,&_dow);//Ler Data
      ds1307_get_time(&_hora,&_min,&_seg);//Ler Hora

      Fprintf(Modem,"\r\n%02d/\%02d/\%02d",_dia,_mes,_ano);//Exibir
      Fprintf(Modem,"\r\n%02d:\%02d:\%02d",_hora,_min,_seg);//Exibir
      delay_ms(1000);
      */
     
   /*   
   set_adc_channel_mcp(0);
   delay_ms(1000);
   analogica_1=read_adc_mcp();
   Fprintf(Modem,"\r\n 1: %ld",analogica_1);//Exibir
   set_adc_channel_mcp(1);
   delay_ms(1000);
   analogica_2=read_adc_mcp();
   Fprintf(Modem,"\r\n 2: %ld",analogica_2);//Exibir
   set_adc_channel_mcp(2);
   delay_ms(1000);
   analogica_3=read_adc_mcp();
   Fprintf(Modem,"\r\n 3: %ld",analogica_3);//Exibir
   set_adc_channel_mcp(3);
   delay_ms(1000);
   analogica_4=read_adc_mcp();
   Fprintf(Modem,"\r\n 4: %ld",analogica_4);//Exibir
   */
   }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 23, 2015 7:37 pm     Reply with quote

Quote:
enable_interrupts(INT_RTCC);
enable_interrupts(INT_EXT);
enable_interrupts(INT_EXT1);
enable_interrupts(INT_EXT2);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

You have no interrupt routines for any of these interrupts.

Quote:
while(TRUE)
{
int a,b;

While(1){

write_ext_eeprom(a,10);
b = read_ext_eeprom(10);

The address 'a' is never initialized to a specific address.

Quote:
ds1307_set_date_time(16,06,2015,0,20,48,00);

The ds1307 driver doesn't support a 4-digit year. Only two digits.


Quote:
write_ext_eeprom(a,10);
b = read_ext_eeprom(10);

You are writing the value of 10 to address 'a'. Then you read address 10.
But you didn't write to address 10. You wrote to address 'a'.


Basically, you didn't read the manual or the driver specifications, given
in each driver file.
lucasromeiro



Joined: 27 Mar 2010
Posts: 167

View user's profile Send private message

PostPosted: Tue Jun 23, 2015 7:56 pm     Reply with quote

PCM programmer wrote:
Quote:
enable_interrupts(INT_RTCC);
enable_interrupts(INT_EXT);
enable_interrupts(INT_EXT1);
enable_interrupts(INT_EXT2);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

You have no interrupt routines for any of these interrupts.

Quote:
while(TRUE)
{
int a,b;

While(1){

write_ext_eeprom(a,10);
b = read_ext_eeprom(10);

The address 'a' is never initialized to a specific address.

Quote:
ds1307_set_date_time(16,06,2015,0,20,48,00);

The ds1307 driver doesn't support a 4-digit year. Only two digits.


Quote:
write_ext_eeprom(a,10);
b = read_ext_eeprom(10);

You are writing the value of 10 to address 'a'. Then you read address 10.
But you didn't write to address 10. You wrote to address 'a'.


Basically, you didn't read the manual or the driver specifications, given
in each driver file.






I removed the functions interrupt because station empty.

This was the last test I did, already tested fixed values in recording and reading memory and did not work!
I had already tested this code before and did not work:
      While (1) {
   

    write_ext_eeprom (10,10);
    b = read_ext_eeprom (10);
    Fprintf (Modem, "\ r \ n% d", b);

    delay_ms (1000);
   }

As the change in the adjustment handle the DS1307, the date changed to the format below and the same error occurs, time does not increases and nothing works!
00/02/01
0:00:00

I believe that the problem is being in something of communication ..
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 23, 2015 8:17 pm     Reply with quote

Run this i2c bus scanner progam and see if it finds your i2c chips.
http://www.ccsinfo.com/forum/viewtopic.php?t=49713
Post the results.
lucasromeiro



Joined: 27 Mar 2010
Posts: 167

View user's profile Send private message

PostPosted: Tue Jun 23, 2015 8:27 pm     Reply with quote

PCM programmer wrote:
Run this i2c bus scanner progam and see if it finds your i2c chips.
http://www.ccsinfo.com/forum/viewtopic.php?t=49713
Post the results.



RESULT OF TEST:

*p:▒Utu▒ACK addr: A6
ACK addr: D0

Number of i2c chips found: 2▒hE▒▒▒▒
ACK addr: A6
ACK addr: D0

Number of i2c chips found: 2ACK addr: A6
ACK addr: D0

Number of i2c chips found: 2▒▒hE▒▒▒▒
ACK addr: A6
ACK addr: D0

Number of i2c chips found: 2
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 23, 2015 8:50 pm     Reply with quote

The ds1307 has a slave address of 0xD0. The MCP3424 also has a default
slave address of 0xD0. This will not work. There is an address conflict.
But, it can be fixed.

The MCP3424 can be configured to use a different slave address.
If you connect the Adr0 pin to ground, and leave Adr1 un-connected,
the slave address will be changed to 0xD2. Then you can edit the
MCP342x.c file and change the following line to use 0xD2 as shown below:
Code:
#define MCP342X_DEVICE_CODE       0xD2


Make that change to your board and run the i2c bus scanner program
again.
lucasromeiro



Joined: 27 Mar 2010
Posts: 167

View user's profile Send private message

PostPosted: Tue Jun 23, 2015 9:20 pm     Reply with quote

PCM programmer wrote:
The ds1307 has a slave address of 0xD0. The MCP3424 also has a default
slave address of 0xD0. This will not work. There is an address conflict.
But, it can be fixed.

The MCP3424 can be configured to use a different slave address.
If you connect the Adr0 pin to ground, and leave Adr1 un-connected,
the slave address will be changed to 0xD2. Then you can edit the
MCP342x.c file and change the following line to use 0xD2 as shown below:
Code:
#define MCP342X_DEVICE_CODE       0xD2


Make that change to your board and run the i2c bus scanner program
again.


Result of scanner:

ACK addr: A6
ACK addr: D0
ACK addr: D2

Number of i2c chips found: 3
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 23, 2015 9:26 pm     Reply with quote

Now you can edit the MCP342x.c file and change the following line to use
0xD2 as shown below:
Code:
#define MCP342X_DEVICE_CODE       0xD2

Then compile and start testing your program again.
lucasromeiro



Joined: 27 Mar 2010
Posts: 167

View user's profile Send private message

PostPosted: Tue Jun 23, 2015 10:10 pm     Reply with quote

PCM programmer wrote:
Now you can edit the MCP342x.c file and change the following line to use
0xD2 as shown below:
Code:
#define MCP342X_DEVICE_CODE       0xD2

Then compile and start testing your program again.



UHULLLL

Now ALL work!!

look:
10
16/06/15
20:49:43
1: 2
2: 131071
3: 2
4: 2

TKS man
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