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

rs232 in header
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
sebalitter



Joined: 05 May 2015
Posts: 47

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

rs232 in header
PostPosted: Thu Jan 23, 2020 10:35 pm     Reply with quote

Hello
This code shows me those errors:

Error#7 Invalid Pre-Processor directive Invalid Pin
Error#12 Undefined identifier SERIAL_GPS

What I'm doing wrong?

fases.c
Code:

// Voltimetro trifasico
#include "fases_header.h"

//#define VSS_VREF
//#define VREF_ADC_1v024                 

#INT_RDA
void  RDA_isr(void)
{
   int8 d;
   d=0;
   d=getchar(SERIAL_GSM);
   clear_interrupt(INT_RDA);
}


void main (void)
{
 
    inicializacion();
   
    //int8 posicion=0;
   
    while(TRUE)
    {
         
        setup_adc_ports(sAN0|sAN2|sAN3);     
        setup_adc(ADC_CLOCK_DIV_2);
       
        voltajes[0] = medir_voltaje(0);
        delay_ms(100);
        voltajes[1] = medir_voltaje(2);
        delay_ms(100);
        voltajes[2] = medir_voltaje(3);
        delay_ms(100);
       
        lcd_gotoxy(0,1);
        printf(lcd_putc," Vr    Vs    Vt");
        lcd_gotoxy(0,2);
        printf(lcd_putc,"%3.0lu    %3.0lu   %3.0lu",voltajes[0], voltajes[1], voltajes[2]);
   
       
         
    }
 
}



Code:

#include <16F1823.h>

#device adc=10
//#device PASS_STRINGS = IN_RAM
 
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOMCLR                   //Master Clear pin enabled
#use delay(clock=16M)            //Configuracion reloj interno

#PIN_SELECT U1TX=PIN_C4
#PIN_SELECT U1RX=PIN_C3

#use rs232(UART, BAUD=9600, PARITY=N, BITS=8, stream=SERIAL_GSM , errors)
#use i2c(Master,Fast=100000, sda=PIN_C1, scl=PIN_C2,force_sw)

#include <i2c_Flex_LCD.c>


#define PROM 1500
#define TELEFONO "1565404122"

int16 voltajes[3];

void inicializacionSIM800L(void)
{
   
    int cont;
    delay_ms(1000);
    puts("A",SERIAL_GSM);  //para sincronizar el baudrate del SIM 900
    delay_ms(300);
    putchar(0x0d,SERIAL_GSM);
    delay_ms(3000);
    for(cont=0;cont<5;cont++)   // mando varios AT para el autobauding
    {
        puts("AT",SERIAL_GSM);
        delay_ms(300);
        putchar(0x0d,SERIAL_GSM);
        delay_ms(200);
       
    }
    puts("AT+CMGF=1\r",SERIAL_GSM);  // configuro para que trabaje en modo texto
    delay_ms(100);
    putchar(0x0d,SERIAL_GSM);
    delay_ms(100);
    puts("AT\r",SERIAL_GPS);
    delay_ms(1000);
    puts("AT+CGPSPWR=1\r",SERIAL_GPS);
    delay_ms(300);     
    puts("AT+CGPSRST=0\r",SERIAL_GPS);
    delay_ms(3000);
    return;
}

void inicializacion(){
    lcd_init();
    lcd_backlight_led(ON); //Enciende la luz de Fondo
    inicializacionSIM800L();
   
    lcd_clear();  //Limpia el LCD
    printf(lcd_putc, "\f");
    enable_interrupts(INT_RDA);
    enable_interrupts(GLOBAL);
}




void mandar_SMS(char *numero , char *mensaje) 
{   
    //char *serial_gsm;
    //sprintf( serial_gsm ,"\n\r LDR Analog Value: %.0f \n\r PANIC Status: %d \n\r TEMP Analog Value: %.0f \n\r X/Y/Z Accelerometer  %.0f : %.0f : %.0f \n\r",ADC1, input(PANIC),grados,i,a,w);
   
    //PIN_ON(LED);
    //delay_ms(300);
   
    //printf(usb_cdc_putc, "\r\nAT+CMGS=\"%s\"\r", numero);
    fprintf(SERIAL_GSM, "AT+CMGS=\"%s\"\r", TELEFONO);
   
    delay_ms(300);
    //fputs(serial_gsm,SERIAL_GSM); 
    fprintf(SERIAL_GSM,"\n\r Vr: %3.0lu  \n\r Vs :%3.0lu \n\r Vt: %3.0lu",voltajes[0], voltajes[1], voltajes[2]);
    //fprintf(SERIAL_GSM, "AT+CMGS=\"%s\"\r", numero);
    delay_ms(100);
    fprintf(SERIAL_GSM,"%c",0x1a);   
    //PIN_OFF(LED);
   
}

int16 medir_voltaje(int8 channel){
    int32 acum=0;
    int16 Vmedio=0, i=0;  //, Voltaje=0;
    for(i=0;i<PROM;i++)
        { 
         set_adc_channel(channel);
         delay_us(100);
         acum+=read_adc();
        }   
    Vmedio=acum/PROM;

    //Voltaje=;
    //lcd_gotoxy(1,1);
    //printf(lcd_putc,"Vr= %lu V",Voltaje);
    return (Vmedio*3.594);
}


Thanks!
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Thu Jan 23, 2020 11:52 pm     Reply with quote

Hint:

UART != UART1

#USE RS232 needs a UART number.
sebalitter



Joined: 05 May 2015
Posts: 47

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

PostPosted: Fri Jan 24, 2020 3:06 am     Reply with quote

Ttelmah wrote:
Hint:

UART != UART1

#USE RS232 needs a UART number.



i changed to UART1 using the conventional ports
Tx: Pin C4
Rx: Pin C5

#use rs232(UART1, BAUD=9600, PARITY=N, BITS=8, stream=SERIAL_GSM , errors)

do you know if i need something else to send a message in sim800L because its not sending anything.
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jan 24, 2020 5:37 am     Reply with quote

Always best to start with the hardware
1) what is the VDD of the PIC ?
2) what is the VDD of the SIM800L?
3) is the SIM800L a 'chip' or a 'module' ?
4) What is the rating of the power supply in amps ?
sebalitter



Joined: 05 May 2015
Posts: 47

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

PostPosted: Fri Jan 24, 2020 5:56 am     Reply with quote

temtronic wrote:
Always best to start with the hardware
1) what is the VDD of the PIC ?
2) what is the VDD of the SIM800L?
3) is the SIM800L a 'chip' or a 'module' ?
4) What is the rating of the power supply in amps ?


Hello , thanks for the quick answer .

PIC16F1823 and SIM800L are connected to the same power ( 5v , 1.25A)

Module GSM SIN800L (Rohs)
[img]
http://g03.a.alicdn.com/kf/HTB1duFfKVXXXXXGaXXXq6xXFXXXq/High-Quality-SIM800L-font-b-GPRS-b-font-GSM-Board-Quadband-QUAD-BAND-L-shape-font.jpg
[/img]


i did something like this
Code:

#INT_RDA
void  RDA_isr(void)
{
   int8 d;
   d=0;
   d=getchar(SERIAL_GSM);
   dato_recibido[con_recepcion] = d;
   con_recepcion++;
   if(con_recepcion>19)
       con_recepcion=0;
   //lcd_gotoxy(0,1);
  // printf(lcd_putc, "%c",d);
   clear_interrupt(INT_RDA);
}

and show it in main..

if(con_recepcion>18){
            lcd_clear();  //Limpia el LCD
            printf(lcd_putc, "\f");
            lcd_gotoxy(0,1);
            printf(lcd_putc,"%s",dato_recibido);
            delay_ms(5000);
        }




but it didnt show anything.
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jan 24, 2020 5:59 am     Reply with quote

Is that module designed to be operated at 5 volts ?
Most peripheral devices are 3 volts and need 'logic level converters' to properly connect to 5 volt PICs.

If you have a 'link' to the module we can check.

hmm, my 'guy instinct' is that you should have at least a 2.5 amp power supply. most of these 'wireless' module need a LOT of current to transmit. whatever the datasheet says DOUBLE it ! You need a good reservoir of electrons !

As for software, check with the mfrs website / dtasheet. there should be some basic 'write to a register, read to confirm' code. Assuming you didn't write the 'driver' code, ask that programmer or check the website/forum for Q&A about it or use Google for THAT device, version of PCB may be a problem ? Code written for V1.2 versus PCB is V2.4.

Jay
sebalitter



Joined: 05 May 2015
Posts: 47

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

PostPosted: Fri Jan 24, 2020 6:08 am     Reply with quote

temtronic wrote:
Is that module designed to be operated at 5 volts ?
Most peripheral devices are 3 volts and need 'logic level converters' to properly connect to 5 volt PICs.

If you have a 'link' to the module we can check.
Jay


it has a VCC input , it says 5v on the board.

[url]
https://irishelectronics.ie/SIM800L-V20-5V-Wireless-GSM-GPRS-MODULE
[/url]
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jan 24, 2020 6:39 am     Reply with quote

hmm I saw this. about 1/2 way down that webpage....

•Embedded AT (optional)

That to me says 'AT command set is an OPTION' though it could mean something totally without the actual datasheet I can't tell.
You should try a simple 'loopback' test to confirm the PIC is running and sending/reciving serial data.

There's 2 possible problems
1) The PIC is not running properly
or
2) The SIM is not running properly

silly question... you have PIC XMT -> SIM RCV ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Fri Jan 24, 2020 8:24 am     Reply with quote

You have a voltage problem.
The SIM800, is a 3.3v device (actually supports 4.4v maximum).
The boards supplied for things like the Arduino, have a regulator to give
the 3.3v, but they don't have a signal amplifier to raise the output voltage
to the levels required by the PIC. The reason is that the PIC serial input
is a Schmitt input but the Arduino one is TTL. So one is not needed when
attached to an Arduino, but is for the PIC,
You need a level shifter on the output from the modem to work.

I've used a lot of these units over the years, and this is required unless
you use a 3.3v PIC.
sebalitter



Joined: 05 May 2015
Posts: 47

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

PostPosted: Fri Jan 24, 2020 8:32 am     Reply with quote

Ttelmah wrote:
You have a voltage problem.
The SIM800, is a 3.3v device (actually supports 4.4v maximum).
The boards supplied for things like the Arduino, have a regulator to give
the 3.3v, but they don't have a signal amplifier to raise the output voltage
to the levels required by the PIC. The reason is that the PIC serial input
is a Schmitt input but the Arduino one is TTL. So one is not needed when
attached to an Arduino, but is for the PIC,
You need a level shifter on the output from the modem to work.

I've used a lot of these units over the years, and this is required unless
you use a 3.3v PIC.


It's working properly now, I wasn't showing the message in the correct position.
The thing is that I can't send SMS yet. I think I have a problem with AT commands.
Also this PIC has a limited memory ram and rom for this program.


main.c
Code:

// Voltimetro trifasico
#include "fases_header.h"

//#define VSS_VREF
//#define VREF_ADC_1v024                 

#INT_RDA
void  RDA_isr(void)
{
   
   dato_recibido[con_recepcion] = getchar(SERIAL_GSM);
   con_recepcion++;
   if(con_recepcion>30)
       con_recepcion=0;
   clear_interrupt(INT_RDA);
}


void main (void)
{
 
    inicializacion();
   
   
    while(TRUE)
    {
         
       
        voltajes[0] = medir_voltaje(0);
        delay_ms(100);
        voltajes[1] = medir_voltaje(2);
        delay_ms(100);
        voltajes[2] = medir_voltaje(3);
        delay_ms(100);
       
        lcd_clear();  //Limpia el LCD
        printf(lcd_putc, "\f");
        lcd_gotoxy(0,1);
        printf(lcd_putc,"%s",&(dato_recibido[0]));
        //printf(lcd_putc," Vr    Vs    Vt");
        lcd_gotoxy(0,2);
        printf(lcd_putc,"%s",&(dato_recibido[15]));
        delay_ms(3000);
        //printf(lcd_putc,"%3.0lu    %3.0lu   %3.0lu",voltajes[0], voltajes[1], voltajes[2]);
       
           
        mandar_SMS();
        delay_ms(3000);
        //ejecucion();
       
   
    }
 
}



.h
Code:

/*
 UART1 -> modulo GSM 
    Tx: Pin C4
    Rx: Pin C5

 * I2C display -> sda=PIN_C1 -  scl=PIN_C2
 
 */
 

#include <16F1823.h>

#device adc=10
//#device PASS_STRINGS = IN_RAM
 
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOMCLR                   //Master Clear pin enabled
#use delay(clock=16M)            //Configuracion reloj interno


#use rs232(UART1, BAUD=9600, PARITY=N, BITS=8, stream=SERIAL_GSM , errors)
#use i2c(Master,Fast=100000, sda=PIN_C1, scl=PIN_C2,force_sw)

#include <i2c_Flex_LCD.c>


#define PROM 1500
#define TELEFONO "1565404122"

int16 voltajes[3];
char dato_recibido[30]; // Buffer de recepción
int con_recepcion=0;

void inicializacionSIM800L(void)
{
   
    int cont;
    delay_ms(1000);
    puts("A",SERIAL_GSM);  //para sincronizar el baudrate del SIM 900
    delay_ms(300);
    putchar(0x0d,SERIAL_GSM);
    delay_ms(3000);
    for(cont=0;cont<5;cont++)   // mando varios AT para el autobauding
    {
        puts("AT",SERIAL_GSM);
        delay_ms(300);
        putchar(0x0d,SERIAL_GSM);
        delay_ms(200);
       
    }
    puts("AT+CMGF=1\r",SERIAL_GSM);  // configuro para que trabaje en modo texto
    delay_ms(100);
    putchar(0x0d,SERIAL_GSM);
    delay_ms(3000);
    return;
}

void inicializacion(){
   
    enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   setup_adc_ports(sAN0|sAN2|sAN3);     
   setup_adc(ADC_CLOCK_DIV_2);
 
    lcd_init();
    lcd_backlight_led(ON); //Enciende la luz de Fondo
    inicializacionSIM800L();
   
    lcd_clear();  //Limpia el LCD
    //printf(lcd_putc, "\f");
    lcd_gotoxy(0,1);
    printf(lcd_putc," INICIANDO..");
    enable_interrupts(INT_RDA);
    enable_interrupts(GLOBAL);
}


void mandar_SMS() 
{   
    //fprintf(SERIAL_GSM, "AT+CMGS=\"%s\"\r", TELEFONO);
    printf(SERIAL_GSM, "AT+CMGS=\"1565404122\"\r");
   
    delay_ms(300);
    //fputs(serial_gsm,SERIAL_GSM);
    //printf(SERIAL_GSM, "SEBA!!!");
    fprintf(SERIAL_GSM,"\n\r Vr: %3.0lu  \n\r Vs :%3.0lu \n\r Vt: %3.0lu",voltajes[0], voltajes[1], voltajes[2]);
   
    //fprintf(SERIAL_GSM, "AT+CMGS=\"%s\"\r", numero);
    delay_ms(100);
    //putchar(0x1a,SERIAL_GSM);
    fprintf(SERIAL_GSM,"%c",0x1a);   

   
}

int16 medir_voltaje(int8 channel){
    int32 acum=0;
    int16 i=0;
    for(i=0;i<PROM;i++)
        { 
         set_adc_channel(channel);
         delay_us(100);
         acum+=read_adc();
        }   
    //Vmedio=;

    return ((acum/PROM)*3.594);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Fri Jan 24, 2020 8:54 am     Reply with quote

OK. Looking at the picture of your board, the two transistors between
the modem, and the connector may be used for level translation. Very Happy

You don't need the clear_interrupt line in your interrupt handler. The
compiler already does this for you.

Little bit puzzled. You refer to SIM900, but the board you show is a
SIM800?.

The telephone number fed to the modem for a SMS, needs to be in
E123 format. They like not to respond unless this is right.

You are also mixing using printf, and fprintf. You need to only use
fprintf.

I know you are limited on space, but normally you need to perform a
AT+CREG to verify the modem has actually registered on the network
before sending.

You also normally need AT+CMGF=1 to set the modem to send SMS's
in text mode. It defaults to working in PDU mode.
sebalitter



Joined: 05 May 2015
Posts: 47

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

PostPosted: Tue Jan 28, 2020 12:35 pm     Reply with quote

I could see the messages in the PC via RS232.
The problem is +CREG: 1,3 (registration denied).
PrinceNai



Joined: 31 Oct 2016
Posts: 479
Location: Montenegro

View user's profile Send private message

PostPosted: Tue Jan 28, 2020 2:11 pm     Reply with quote

I did a quick search on the net and saw there are a lot of people out there having that problem with SIM800 modules. One of the reasons they mention is a duplicate IMEI number and network operators having a list of those. Do you by chance have another module to test with?

As a side note, Chinese modules, both SIM800 and SIM900, gave me nothing but trouble. Not connecting, disconnecting, one day it works and the next day not... So one day I threw all of them into trash bin and got myself some A6 modules. Zero problems, only the ones I created via bad code :-)
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Jan 28, 2020 3:22 pm     Reply with quote

sebalitter wrote:
I could see the messages in the PC via RS232.
The problem is +CREG: 1,3 (registration denied).


What country are you in?

The SIM800 is a 2G module. 2G technology is old, and no longer operational in a lot of countries.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
sebalitter



Joined: 05 May 2015
Posts: 47

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

PostPosted: Sat Feb 15, 2020 11:19 am     Reply with quote

Thank you. With A6 module works perfect. it a bit more expensive but it saves me lots of time.

I have other issue...

Error#7 Invalid Pre-Processor directive Invalid Pin

i didn found #pin_select directive in <16F1823.h>

why does it happend?
why i cant change U1RX pin port?

Code:

#pin_select U1RX = PIN_C3

#use rs232(UART1, BAUD=9600, PARITY=N, BITS=8, stream=SERIAL_GSM , errors)



Another question with sleep mode.
do i need to connect special external interrupt ports in this device? or i can use whatever port i want ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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