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

SW Uart on PCD devices
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kmp84



Joined: 02 Feb 2010
Posts: 345

View user's profile Send private message

PostPosted: Mon Apr 30, 2018 6:22 am     Reply with quote

Hi TT,

Yes, simple getc, putc and printf test example works correct.

Thanks!
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Mon Apr 30, 2018 7:02 am     Reply with quote

You are sure the data format is 'right?. Specify it in the setup. So 8 bits no parity, and double check at the other end.

The only reason it can really go wrong, is that the getc, 'thinks' it has finished, and returns, while the actual incoming data has another low clock which then arrives. This then means the interrupt triggers again, and starts to read incorrect data. Now the sort of thing that would cause this would be (for example) having 9bit data arriving. The software UART does not 'test' for framing errors, so would not report a problem.
kmp84



Joined: 02 Feb 2010
Posts: 345

View user's profile Send private message

PostPosted: Mon Apr 30, 2018 8:04 am     Reply with quote

Mr.TT com. parameters are OK(9600/8/N/1). With those parameters and without ext_int sw_uart work correct! Another strange thing is when debugging, after second byte I sent int_ext fire!
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Mon Apr 30, 2018 11:40 am     Reply with quote

Which says it is seeing a rising edge....
Have you got a logic analyser?.
Pulse a pin when the interrupt handler gets to the end of the getc. Then have the analyser record the incoming data stream from this point.
kmp84



Joined: 02 Feb 2010
Posts: 345

View user's profile Send private message

PostPosted: Wed May 02, 2018 12:23 am     Reply with quote

Hi TT,

I have no logic analyzer, but simple test with push button ext_int fire from low to high transition which is incorrect!
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Wed May 02, 2018 1:11 am     Reply with quote

OK.

A quick look at the listing shows you are hitting a database error with the compiler for this chip....
Code:

//Use this:
#bit INT1EP=getenv("BIT:INT1EP")

#zero_ram
void main(){
   
   delay_ms(500); // wait PLL Lock.
   
   printf("\r\n Hello from 'SW-UART' on DsPic33Ep512MU810");

   INT1EP=TRUE; //falling edge
   clear_interrupt(INT_EXT1); //in case it is set by setting the edge
   ENABLE_INTERRUPTS(INT_EXT1);

   for(;;){
       if(fl){
          putc(c);
          fl = FALSE;
       }
   }
}   

Report this to CCS.

For some reason the compiler is setting bit 5, not bit 1 to control the polarity.
kmp84



Joined: 02 Feb 2010
Posts: 345

View user's profile Send private message

PostPosted: Wed May 02, 2018 5:13 am     Reply with quote

Now INT_EXT fire correct, but the data is wrong!
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Wed May 02, 2018 7:05 am     Reply with quote

What do you mean wrong?. If it is triggering at the right place, then it should give the same as when you use it without interrupts (though you might need the SAMPLE_EARLY option).
What is it giving? If you send 'A' for example, what do you get?.
temtronic



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

View user's profile Send private message

PostPosted: Wed May 02, 2018 8:03 am     Reply with quote

hmm.. I'm wondering if there's maybe no MAX232 between PIC and PC ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Wed May 02, 2018 8:18 am     Reply with quote

He claims though that it works without using the interrupt. Otherwise I'd suspect something similar....
kmp84



Joined: 02 Feb 2010
Posts: 345

View user's profile Send private message

PostPosted: Wed May 02, 2018 12:30 pm     Reply with quote

Hi,

Yes, without using interrupt, getc and putc data are equal. With interrupt using every time I get 0x00.
temtronic



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

View user's profile Send private message

PostPosted: Thu May 03, 2018 5:14 am     Reply with quote

It might be time to post your current code. There's been a LOT of changes in this thread and something might now be obvious, at least it could be tested by others.
kmp84



Joined: 02 Feb 2010
Posts: 345

View user's profile Send private message

PostPosted: Thu May 03, 2018 5:36 am     Reply with quote

temtronic wrote:
It might be time to post your current code.There's been a LOT of changes in this thread and something might now be obvious,at leat it could be tested by others.


I also think so:
Code:
#include <33EP512MU810.h>
#device ICSP=1
#use delay(crystal=8MHz, clock=16MHz)


#FUSES NOWDT                    //No Watch Dog Timer
#FUSES CKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOJTAG                   //JTAG disabled
#FUSES NOPROTECT                //

#bit INT1EP=getenv("BIT:INT1EP")

#pin_select INT1=PIN_G12

#use rs232(baud=9600, xmit=PIN_G13, rcv=PIN_G12, SAMPLE_EARLY)

char c;
int1 fl = FALSE;

#int_ext1
void int1_swuart_isr(void){
   
   c=getc();
   fl = TRUE;
}

#zero_ram
void main(){
   
   char c;
   
   delay_ms(500); // wait PLL Lock.
   
   printf("\r\n Hello from 'SW-UART' on DsPic33Ep512MU810");
   
   INT1EP=TRUE; //falling edge
   //ext_int_edge(INT_EXT1, H_TO_L);
   clear_interrupt(INT_EXT1); //in case it is set by setting the edge
   ENABLE_INTERRUPTS(INT_EXT1);

   for(;;){
      if(fl){
         putc(c);
         fl = FALSE;
      }
     
      //c = getc();  // ok
      //putc(c);     // ok
   }
}


P.S I'm using MAX3232 level convertor.
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 Previous  1, 2
Page 2 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