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

Inverted software UART not working why?? with interrupt on B

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



Joined: 08 Sep 2006
Posts: 182

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

Inverted software UART not working why?? with interrupt on B
PostPosted: Mon Mar 07, 2011 10:08 am     Reply with quote

Hello,

I wanted to work with a software UART.. and still have a interrupt.
So mine receive is on pin B0..
And I enabled mine interupt...
The hardware UART doesn't allow me to use the INVERT optie so that's why I use a software UART. Mine hardware is sending a string with at the end 0x0D. (I checked it)

But why o why is this not working???

Regards,
Jody
include the code.....
Code:

#include "C:\MentorProjects\PIC_Code\Test code_USB\main.h"
#include <stdlib.h>
// Includes all USB code and interrupts, as well as the CDC API
#include <usb_cdc.h>



int1   string_ready   = FALSE;
unsigned int   next_in        = 0;
char   string[45];
int8   teller       = 0;

#int_EXT
void  EXT_isr(void)
{
    string[next_in]=getc();
    if((string[next_in] == 0x0D) & (next_in > 1))   //Einde string
    {
        string_ready = TRUE;
        string[next_in+1] = '\0';
    }
    next_in=(next_in+1);
}


void main()
{
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);


   usb_cdc_init();
     usb_init();

   for(teller = 0; teller < 45; teller++)
    {
        string[teller] = ' ';
    }
    next_in = 0;


   fprintf(out,"SD2\n");

   while(1)
   {
       while(!usb_cdc_connected())
       {
       }
       usb_task();
       if (usb_enumerated())
       {
         if(string_ready == TRUE)
         {
         printf(usb_cdc_putc,"code oke");   
         }      
      }
   }
}

Code:

#include <18F4550.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HSPLL                      //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES DEBUG                    //Debug mode for use with ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOIESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES MCLR                     //Master Clear pin enabled
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL5                     //Divide By 5(20MHz oscillator input)
#FUSES CPUDIV1                  //System Clock by 2
#FUSES USBDIV                   //USB clock source comes from PLL divide by 2
#FUSES VREGEN                   //USB voltage regulator enabled
#FUSES NOICPRT                    //ICPRT enabled

#use delay(clock=20000000)
#use rs232(baud=9600, parity=N,stop=1,xmit=PIN_B1,rcv=PIN_B0,bits=8, invert, stream = out)
//#use rs232(baud=9600,parity=N,stop=1,xmit=PIN_D0,rcv=PIN_D1,bits=8, stream=RFID2)

Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Mon Mar 07, 2011 10:52 am     Reply with quote

With invert, the line will be sitting low, and you need to interrupt on the first rising edge. You need to set the interrupt to interrupt on a rising edge, not a falling edge - this should be the default at power on, but safer to set it.....
Also, change the setup_spi line to setup_spi(FALSE);. This is a long running 'mistake' from the wizard, which results in the spi being enabled....
You really _must_ check 'next_in' does not exceed the size of your buffer, or you risk destroying other important data.
Your clock is not 20MHz. You are running the CPU, from the USB PLL. So with CPUDIV1, the CPU is running at 48MHz. Either change the clock setting to the right value, or change the fuse to 'HS', instead of 'HSPLL'.

Best Wishes
Jody



Joined: 08 Sep 2006
Posts: 182

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

PostPosted: Mon Mar 07, 2011 12:21 pm     Reply with quote

Okee I will check it tomorrow....
As soon as I am in the office..

But THANKS!!!
Jody



Joined: 08 Sep 2006
Posts: 182

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

PostPosted: Tue Mar 08, 2011 4:54 am     Reply with quote

Hello,

I am doing something wrong.....
I see on the scoop that the RB0 pin is high and going low when there is data comming... But mine incomming data is corrupted....
Is mine baud rate oke??? Or doesn't I use getc()..??
Code:

#include "C:\MentorProjects\PIC_Code\RFID Test code_USB\main.h"
#include <stdlib.h>
// Includes all USB code and interrupts, as well as the CDC API
#include <usb_cdc.h>



int1   string_ready   = FALSE;
signed int   next_in        = 0;
char   string[45];
int8   teller       = 0;

#int_EXT
void  EXT_isr(void)
{
   // string[next_in]=((~getc())+1);
   string[next_in]=getc();
    if((string[next_in] == 0x0d) & (next_in > 1))   //Einde string
    {
        string_ready = TRUE;
        string[next_in+1] = '\0';
    }
    next_in=(next_in+1);
}


void main()
{
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   ext_int_edge( H_TO_L );   // Sets up EXT
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);


   usb_cdc_init();
     usb_init();

   for(teller = 0; teller < 45; teller++)
    {
        string[teller] = ' ';
    }
    next_in = 0;

   printf("SD2\r");

   while(1)
   {
       while(!usb_cdc_connected())
       {
       }
       usb_task();
       if (usb_enumerated())
       {
         if(string_ready == TRUE)
         {
         printf(usb_cdc_putc,string);   
         string_ready = FALSE;
         }      
      }
   }
}

Code:

#include <18F4550.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HSPLL                      //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES DEBUG                    //Debug mode for use with ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOIESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES MCLR                     //Master Clear pin enabled
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL5                     //Divide By 4(20MHz oscillator input)
#FUSES CPUDIV2                  //System Clock by 2
#FUSES USBDIV                   //USB clock source comes from PLL divide by 2
#FUSES VREGEN                   //USB voltage regulator enabled
#FUSES NOICPRT                    //ICPRT enabled

#use delay(clock=24000000)
//#use rs232(baud=9600, parity=N,stop=1,xmit=PIN_B1,rcv=PIN_B0,bits=8, sample_early, disable_ints, force_sw)
#use rs232(baud=9600, parity=N,stop=1,xmit=PIN_B1,rcv=PIN_B0,bits=8, disable_ints, force_sw, sample_early)



Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Tue Mar 08, 2011 5:38 am     Reply with quote

OK. So you have changed to not using 'invert', and using standard TTL serial data.

Your clock rate is wrong again. The CPUDIV2 fuse, from the USB PLL, gives operation at 32MHz.

It is moderately complex, and not helped by CCS's nomenclature.

Code:

Divider pattern    CCS name    division from XTAL    division from USB
00                      CPUDIV1       1                             2
01                      CPUDIV2       2                             3
10                      CPUDIV3       3                             4
11                      CPUDIV4       4                             6


So the CPUDIV2 fuse, gives /2, when running from the crystal (which is why CCS chose the name), but /3, when running off the USB PLL, which is what you have got selected. USB master clock is 96MHz, so your CPU is running at 32MHz, not 24MHz. For 24MHz, you need CPUDIV3.....

In your code that accepts the string, you also need to set 'next_in', back to the start of the buffer, or the second string will start walking over other things in memory....

This may be all that is wrong.

Best Wishes
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