|
|
View previous topic :: View next topic |
Author |
Message |
r4ph431dc
Joined: 23 Jul 2018 Posts: 7 Location: Natal,RN-Brazil
|
TBLRD message in proteus. |
Posted: Mon Jul 23, 2018 1:18 pm |
|
|
Hi everyone. I'm new in this forum, but frequently i look for some answers.
I'm using CCS V5.078, proteus 8.7 and pic18lf4550. My question is about this message:
[PIC18 MEMORY] PC=0x00A6. Address for TBLRD*- instruction (0x003FFFFD) is not a valid configuration address - zero returned. [U1]
I'm using two rs232, and i want to start the program after 10 seconds. Well... if put this condition, the message shows up and program doesn't work. When i take off these conditions, the program works fine.
For me this message do not make sense.
Someone could give me some help?
Code: |
//==============================================================================
// CONFIGURAÇÕES INICIAIS
//==============================================================================
#include"18F4550.H"
#device ADC=10
// Escolher entre AD de 8 ou 10 bits. (escolher apenas um)
#define ADC8
//#define ADC10
//_______________________Configuração do oscilador______________________________
#define CLOCK4 4000000
//#define CLOCK10 10000000
//#define CLOCK16 16000000
#ifdef CLOCK4
#fuses INTRC_IO//XT
#use delay (clock=4000000) // define clock de operação
#endif
#ifdef CLOCK10
#fuses HS
#use delay (clock=10000000) // define clock de operação
#endif
#ifdef CLOCK16
#fuses HS
#use delay (clock=16000000) // define clock de operação
#endif
//______________________________________________________________________________
#fuses NOWDT,NOPROTECT,NOLVP,NODEBUG,VREGEN,BROWNOUT,CPUDIV1//,LPT1OSC,IESO // configurações dos fuses
//________________DEFINIÇÃO DOS PINOS___________________________________________
//______________________________RS232___________________________________________
//#use RS232(Baud=9600,xmit=PIN_C6,rcv=PIN_C7, errors)//,TIMEOUT=1000)
#use RS232(Baud=9600,xmit=PIN_C6,rcv=PIN_D3,stream=com_gps, errors)//,TIMEOUT=1000) // habilita comunicação rs232 com o GPS
#use RS232(Baud=9600,xmit=PIN_D7,rcv=PIN_D6,stream=com_sigfox, errors, TIMEOUT=1000) //
#use RS232(Baud=9600,xmit=PIN_A2,rcv=PIN_A3,stream=com_1, errors,TIMEOUT=1000)
#include "MCP9700.c"
#include "GPS.H"
#include "GPS.C"
//==============================================================================
#define gps_ok_on output_high(pin_e2)
#define gps_ok_off output_low(pin_e2)
#define gps_erro_on output_high(pin_e1)
#define gps_erro_off output_low(pin_e1)
#define sistema_ok_on output_high(pin_e0)
#define sistema_ok_off output_low(pin_e0)
#define sistema_erro_on output_high(pin_a5)
#define sistema_erro_off output_low(pin_a5)
#define temp_on output_high(pin_a1)
#define temp_off output_low(pin_a1)
//==============================================================================
int buffer[20];
//==============================================================================
int testa_serial()
{
int i=0,tempout=10;
while(tempout != 0 && buffer[i] != 0x0D)
{
i++;
buffer[i] = fgetc(com_sigfox);
tempout--;
}
if(tempout == 0)
{
return 0;
}
return i;
}
//==============================================================================
void main(void)
{
int1 continua=0;
int dado,cont,ok,i,tentativas=0,j,qtd;
int16 tempo;
#ifdef CLOCK4
int ContTMR0 = 5;
SETUP_TIMER_0(RTCC_INTERNAL | RTCC_DIV_4 | RTCC_8_BIT );
#endif
#ifdef CLOCK10
int ContTMR0 = 101;
SETUP_TIMER_0(RTCC_INTERNAL | RTCC_DIV_16 | RTCC_8_BIT );
#endif
#ifdef CLOCK16
int ContTMR0 = 5;
SETUP_TIMER_0(RTCC_INTERNAL | RTCC_DIV_16 | RTCC_8_BIT );
#endif
SET_RTCC(ContTMR0);
ENABLE_INTERRUPTS(INT_TIMER0);
ENABLE_INTERRUPTS(GLOBAL);
temp_off; // alimentação do sensor desligada
delay_ms(1000);
fprintf(com_1,"\r\n>>AT\r\n");
fprintf(com_sigfox,"\r\nAT\n");
qtd = testa_serial();
fprintf(com_1,"<<");
for(j=1;j<qtd;j++)
{
fprintf(com_1,"%C",buffer[j]);
}
fprintf(com_1,"\r\n");
fprintf(com_1,"\r\n>>GET ID:\r\n");
delay_ms(1);
fprintf(com_sigfox,"AT$I=10\n");
qtd = testa_serial();
fprintf(com_1,"<<");
for(j=1;j<qtd;j++)
{
fprintf(com_1,"%C",buffer[j]);
}
fprintf(com_1,"\r\n");
fprintf(com_1,"\r\n>>GET PAC:\r\n");
delay_ms(1);
fprintf(com_sigfox,"AT$I=11\n");
qtd = testa_serial();
fprintf(com_1,"<<");
for(j=1;j<qtd;j++)
{
fprintf(com_1,"%C",buffer[j]);
}
fprintf(com_1,"\r\n");
fprintf(com_1,">>AT$DR=905200000\r\n");
fprintf(com_sigfox,"AT$DR=905200000\n"); // seleciona frequencia
qtd = testa_serial();
fprintf(com_1,"<<");
for(j=1;j<qtd;j++)
{
fprintf(com_1,"%C",buffer[j]);
}
fprintf(com_1,"\r\n");
fprintf(com_1,">>ATS400=<000001FF><00000000><00000000>,1\r\n");
fprintf(com_sigfox,"ATS400=<000001FF><00000000><00000000>,1\n"); // salva configuração
qtd = testa_serial();
fprintf(com_1,"<<");
for(j=1;j<qtd;j++)
{
fprintf(com_1,"%C",buffer[j]);
}
fprintf(com_1,"\r\n");
fprintf(com_1,">>AT$WR\r\n");
fprintf(com_sigfox,"AT$WR\n"); // salva configuração
qtd = testa_serial();
fprintf(com_1,"<<");
for(j=1;j<qtd;j++)
{
fprintf(com_1,"%C",buffer[j]);
}
fprintf(com_1,"\r\n");
fprintf(com_1,">>AT$RC\r\n");
fprintf(com_sigfox,"AT$RC\n"); // reset o canal
qtd = testa_serial();
fprintf(com_1,"<<");
for(j=1;j<qtd;j++)
{
fprintf(com_1,"%C",buffer[j]);
}
fprintf(com_1,"\r\n");
while(1)
{
fprintf(com_1,">>AT$GI?\r\n");
fprintf(com_sigfox,"\nAT$GI?\n");
qtd = testa_serial();
fprintf(com_1,"<<");
for(j=1;j<qtd;j++)
{
fprintf(com_1,"%C",buffer[j]);
}
fprintf(com_1,"\r\n");
if(buffer[0] == '0' || buffer[2] < 3)
{
fprintf(com_sigfox,"\nAT$RC\n");
}
else
{
fprintf(com_1,">>AT$SF\r\n");
fprintf(com_sigfox,"\nAT$SF=");
fprintf(com_sigfox,"%X%X%X%X\n",3,1,3,2);
qtd = testa_serial();
fprintf(com_1,"<<");
for(j=1;j<qtd;j++)
{
fprintf(com_1,"%C",buffer[j]);
}
fprintf(com_1,"\r\n");
}
delay_ms(5000);
}
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Mon Jul 23, 2018 2:03 pm |
|
|
Please clarify, the message appear in the Proteus simulation or in realtime, using real hardware ? |
|
|
r4ph431dc
Joined: 23 Jul 2018 Posts: 7 Location: Natal,RN-Brazil
|
|
Posted: Mon Jul 23, 2018 2:52 pm |
|
|
Hi. This message appers in simulation and the program comunication doesn't work. When execute any routine from rs232, the message shows again. When i program the pic and put it to work in real world, doesn't work. |
|
|
r4ph431dc
Joined: 23 Jul 2018 Posts: 7 Location: Natal,RN-Brazil
|
|
Posted: Mon Jul 23, 2018 3:37 pm |
|
|
temtronic wrote: | Please clarify, the message appear in the Proteus simulation or in realtime, using real hardware ? |
Hi. This message appers in simulation and the program comunication doesn't work. When execute any rotine from rs232, the message shows again. When i program the pic and put it to work in real world, doesn't work.
This is a print https://www.flickr.com/photos/raphaeldc/28710333947/in/dateposted-public/ |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 23, 2018 3:49 pm |
|
|
Quote: | My question is about this message:
[PIC18 MEMORY] PC=0x00A6. Address for TBLRD*- instruction (0x003FFFFD) is not a valid configuration address - zero returned. [U1] |
It's probably a Proteus bug.
Quote: | ENABLE_INTERRUPTS(INT_TIMER0);
ENABLE_INTERRUPTS(GLOBAL); |
I don't see an #int_timer0 interrupt routine in your posted code.
Do you have one ? You need it.
All of these are software UARTs:
Quote: |
#use RS232(Baud=9600,xmit=PIN_C6,rcv=PIN_D3,stream=com_gps, errors)//,TIMEOUT=1000) // habilita comunicação rs232 com o GPS
#use RS232(Baud=9600,xmit=PIN_D7,rcv=PIN_D6,stream=com_sigfox, errors, TIMEOUT=1000) //
#use RS232(Baud=9600,xmit=PIN_A2,rcv=PIN_A3,stream=com_1, errors,TIMEOUT=1000)
|
Read about the DISABLE_INTS parameter in the CCS manual:
Quote: | DISABLE_INTS -
Will cause interrupts to be disabled when the routines get or put a
character. This prevents character distortion for software implemented I/O
and prevents interaction between I/O in interrupt handlers and the main
program when using the UART. |
You need to add the parameters shown in bold below:
Quote: | #use RS232(Baud=9600,xmit=PIN_C6,rcv=PIN_D3,stream=com_gps, errors, DISABLE_INTS)
#use RS232(Baud=9600,xmit=PIN_D7,rcv=PIN_D6,stream=com_sigfox, errors, TIMEOUT=1000, DISABLE_INTS)
#use RS232(Baud=9600,xmit=PIN_A2,rcv=PIN_A3,stream=com_1, errors,TIMEOUT=1000, DISABLE_INTS) |
You appear to have only one fgetc() statement:
Quote: | buffer[i] = fgetc(com_sigfox); |
Because it uses a software UART, it will sit and wait for an incoming
character. During that time, interrupts will be disabled (if you use the
DISABLE_INTS parameter). For this reason, the com_sigfox stream
should be configured for a hardware UART. i.e., xmit=PIN_C6, rcv=PIN_C7. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Mon Jul 23, 2018 5:25 pm |
|
|
Now you KNOW why a lot of us keep saying DO NOT USE PROTEUS !
It doesn't work properly, it's busted, broke,incomplete..
Even the 'schematic' is in error... build it as shown, it cannot work.
Also, unless you're need to use the internal USB of the 4550, use another PIC and a $2 USB<>TTL module. Cheaper hardware, NO software and NO codespace required.
Jay |
|
|
r4ph431dc
Joined: 23 Jul 2018 Posts: 7 Location: Natal,RN-Brazil
|
|
Posted: Mon Jul 23, 2018 5:58 pm |
|
|
PCM programmer wrote: | Quote: | My question is about this message:
[PIC18 MEMORY] PC=0x00A6. Address for TBLRD*- instruction (0x003FFFFD) is not a valid configuration address - zero returned. [U1] |
It's probably a Proteus bug.
Quote: | ENABLE_INTERRUPTS(INT_TIMER0);
ENABLE_INTERRUPTS(GLOBAL); |
I don't see an #int_timer0 interrupt routine in your posted code.
Do you have one ? You need it.
All of these are software UARTs:
Quote: |
#use RS232(Baud=9600,xmit=PIN_C6,rcv=PIN_D3,stream=com_gps, errors)//,TIMEOUT=1000) // habilita comunicação rs232 com o GPS
#use RS232(Baud=9600,xmit=PIN_D7,rcv=PIN_D6,stream=com_sigfox, errors, TIMEOUT=1000) //
#use RS232(Baud=9600,xmit=PIN_A2,rcv=PIN_A3,stream=com_1, errors,TIMEOUT=1000)
|
Read about the DISABLE_INTS parameter in the CCS manual:
Quote: | DISABLE_INTS -
Will cause interrupts to be disabled when the routines get or put a
character. This prevents character distortion for software implemented I/O
and prevents interaction between I/O in interrupt handlers and the main
program when using the UART. |
You need to add the parameters shown in bold below:
Quote: | #use RS232(Baud=9600,xmit=PIN_C6,rcv=PIN_D3,stream=com_gps, errors, DISABLE_INTS)
#use RS232(Baud=9600,xmit=PIN_D7,rcv=PIN_D6,stream=com_sigfox, errors, TIMEOUT=1000, DISABLE_INTS)
#use RS232(Baud=9600,xmit=PIN_A2,rcv=PIN_A3,stream=com_1, errors,TIMEOUT=1000, DISABLE_INTS) |
You appear to have only one fgetc() statement:
Quote: | buffer[i] = fgetc(com_sigfox); |
Because it uses a software UART, it will sit and wait for an incoming
character. During that time, interrupts will be disabled (if you use the
DISABLE_INTS parameter). For this reason, the com_sigfox stream
should be configured for a hardware UART. i.e., xmit=PIN_C6, rcv=PIN_C7. |
In this code, I'm not using timer yet. I'll remove it and test again.
As the spi and uart are in the same pin in 18f4550, i left the spi and changed the uart.
I'll clean up the code and test your suggestions. |
|
|
r4ph431dc
Joined: 23 Jul 2018 Posts: 7 Location: Natal,RN-Brazil
|
|
Posted: Mon Jul 23, 2018 6:11 pm |
|
|
temtronic wrote: | Now you KNOW why a lot of us keep saying DO NOT USE PROTEUS !
It doesn't work properly, it's busted, broke,incomplete..
Even the 'schematic' is in error... build it as shown, it cannot work.
Also, unless you're need to use the internal USB of the 4550, use another PIC and a $2 USB<>TTL module. Cheaper hardware, NO software and NO codespace required.
Jay |
Unfortunately this is the way that i see to check the code before program the hardware.
I only have this pic, but i'm looking for another one that has more memory than this and don't have usb. Do you can recommend another pic? I bought the pic18lf47k42. Have you use it? And... how could i test my programs without proteus? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Tue Jul 24, 2018 1:48 am |
|
|
Almost certainly the error is having the interrupt enabled with no handler.
However there is an issue with your clock settings. You have 'CLOCK4' selected. This selects INT_RC. The default clock given by INT_RC on this chip is 8MHz, not 4MHz....
This will stop the serials from working in the 'real' chip.
I don't think Proteus will work with software UART's which you are using, so the code is not going to work in Proteus.
The 18x47K42 is a nice chip.
However are you going to be building at 3.3v?. The LF version you have is rated for 3.6v _max_. Also you are going to have to learn how to use #PIN_SELECT (look at the sticky at the top of the forum), since most peripherals on this use PPS. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Tue Jul 24, 2018 5:04 am |
|
|
comments.
I've been using the PIC18F46K22 for a few years,even for small projects. Back then it seemed lke a good choice. 40 pins so lots of I/O, 2 hardware UARTs( almost necessary today), 64K of memory, lots of RAM and a fast,internal clock. I dedicate the ICSP pins to just ICSP, typically use a 20x04 LCD module, I2C RTC, 3x4 KPD,USB<>TTL for PC data and other stuff and have never run out of pins.There's also one for the '1Hz flashing LED' ! By staying with one PIC, I've built up a library of known,solid functions and drivers so very little time is spent on 'why doesn't this work' problems associated with the 'newest and bestest' PIC.
I remember when the 4550 came out, one of the first with internal USB. Quickly decided it was better to use an external USB<>TTL module. The benefits included it was cheaper($2) than buying all the parts(connector,reistors,LEDs,etc.) and integrating onto a PCB.Flipping D+ and D- wasn't fun either ,arrgh. From the software side, no 'driver' is required,all the magic is done inside the module. You also save codespace. I recall the full CCS driver took maybe 1/4 or mode of EEPROM. A hardware benefit is that any I/O pins can become USB pins,though not interrupt driven,you can code around that.
As for simulation, I let the Real World show me what's going on. I started programming on PDP8s with teletypes and papertape. Back then you did a lot of 'simulation' using paper and pencil BEFORE punching any tape. The huge problem with Proteus is that it is NOT reliable.100s of flaws,bad DRC,errors yet people still use it,beliving that what it says is true. Hardware these days is inexpensive,even I now buy modules from China as I can't buy parts and make a PCB for them.
The 46K22 has a 28 pin smaller sister,just fewer pins but simialr features. Also that PIC will run 3 and 5 vlts, so it's compatible with external peripherals that all seem to be 3 volt devices. I've even got 5V LCD modules to run on 3V PICs, needs 4 small parts and a clock source. needed to do that as 3 volt LCDs are $$$!
Jay |
|
|
r4ph431dc
Joined: 23 Jul 2018 Posts: 7 Location: Natal,RN-Brazil
|
|
Posted: Tue Jul 24, 2018 5:23 am |
|
|
Ttelmah wrote: | Almost certainly the error is having the interrupt enabled with no handler.
However there is an issue with your clock settings. You have 'CLOCK4' selected. This selects INT_RC. The default clock given by INT_RC on this chip is 8MHz, not 4MHz....
This will stop the serials from working in the 'real' chip.
I don't think Proteus will work with software UART's which you are using, so the code is not going to work in Proteus.
The 18x47K42 is a nice chip.
However are you going to be building at 3.3v?. The LF version you have is rated for 3.6v _max_. Also you are going to have to learn how to use #PIN_SELECT (look at the sticky at the top of the forum), since most peripherals on this use PPS. |
Yes. The problem was that. I removed the command to enable interrupts and it worked. I enabled and put the routine and it worked.
And yes, I'm building in 3.3V. |
|
|
r4ph431dc
Joined: 23 Jul 2018 Posts: 7 Location: Natal,RN-Brazil
|
|
Posted: Tue Jul 24, 2018 5:30 am |
|
|
temtronic wrote: | comments.
I've been using the PIC18F46K22 for a few years,even for small projects. Back then it seemed lke a good choice. 40 pins so lots of I/O, 2 hardware UARTs( almost necessary today), 64K of memory, lots of RAM and a fast,internal clock. I dedicate the ICSP pins to just ICSP, typically use a 20x04 LCD module, I2C RTC, 3x4 KPD,USB<>TTL for PC data and other stuff and have never run out of pins.There's also one for the '1Hz flashing LED' ! By staying with one PIC, I've built up a library of known,solid functions and drivers so very little time is spent on 'why doesn't this work' problems associated with the 'newest and bestest' PIC.
I remember when the 4550 came out, one of the first with internal USB. Quickly decided it was better to use an external USB<>TTL module. The benefits included it was cheaper($2) than buying all the parts(connector,reistors,LEDs,etc.) and integrating onto a PCB.Flipping D+ and D- wasn't fun either ,arrgh. From the software side, no 'driver' is required,all the magic is done inside the module. You also save codespace. I recall the full CCS driver took maybe 1/4 or mode of EEPROM. A hardware benefit is that any I/O pins can become USB pins,though not interrupt driven,you can code around that.
As for simulation, I let the Real World show me what's going on. I started programming on PDP8s with teletypes and papertape. Back then you did a lot of 'simulation' using paper and pencil BEFORE punching any tape. The huge problem with Proteus is that it is NOT reliable.100s of flaws,bad DRC,errors yet people still use it,beliving that what it says is true. Hardware these days is inexpensive,even I now buy modules from China as I can't buy parts and make a PCB for them.
The 46K22 has a 28 pin smaller sister,just fewer pins but simialr features. Also that PIC will run 3 and 5 vlts, so it's compatible with external peripherals that all seem to be 3 volt devices. I've even got 5V LCD modules to run on 3V PICs, needs 4 small parts and a clock source. needed to do that as 3 volt LCDs are $$$!
Jay |
Ok. Thank you so much for your reply. I'll buy some to test.
Thanks a lot guys! |
|
|
|
|
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
|