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

PIC18F25K80 UART and ECAN problems [SOLVED]

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



Joined: 30 Jan 2015
Posts: 8

View user's profile Send private message

PIC18F25K80 UART and ECAN problems [SOLVED]
PostPosted: Fri Jan 30, 2015 9:43 am     Reply with quote

Hello,
I have two boards with PIC18F25K80 connected via ECAN (MCP2551 and resistors).
I am using INTRC_IO.
Here is a code for RX board (#define BOARDRX 1 uncommented).
CAN isnt work, also from UART I have a lot of errors (Iam using MAX232)
UART example:
Iam running@@@
RX[H���+��


Code:

#include <18F25K80.h>
#fuses INTRC_IO,NOWDT,PUT,NOPROTECT,NOMCLR,NOCPD,BROWNOUT,NOIESO,NOFCMEN

#use delay(clock=4000000)

//xmit=PIN_C6,rcv=PIN_C7
#use rs232(uart1,baud=9600,bits=8,parity=N,stop=1)

#define BLINKER PIN_C0

//#define BOARDTX 1
#define BOARDRX 1

#define CAN_USE_EXTENDED_ID FALSE
#include <can-18xxx8.c>


void main() {


   struct rx_stat rxstat;
   int32 rx_id;
   int in_data[8];
   int rx_len;

//send a request (tx_rtr=1) for 8 bytes of data (tx_len=8) from id 24 (tx_id=24)
   int out_data[8];
   int32 tx_id=24;
   //int1 tx_rtr=1;
   //int1 tx_ext=0;
   int1 tx_rtr=0; 
   int1 tx_ext=1; 
   int tx_len=8;
   int tx_pri=3;
   int i;


   can_init();
   
   //can_set_mode(CAN_OP_LOOPBACK);
   
   delay_ms(1000);
   output_high(BLINKER);
   delay_ms(500);
   output_low(BLINKER);
 
   delay_ms(300);
   printf("\nuC OK\n");
   delay_ms(300);
   
   while(TRUE)
   {
   delay_ms(600);
   printf("\nIam running");
   delay_ms(600);
   
   delay_ms(1000);
   output_high(BLINKER);
   delay_ms(500);
   output_low(BLINKER);
   delay_ms(500);
   

#ifdef BOARDRX
      printf("\n RX MODE ");
      delay_ms(800);
      if ( can_kbhit() )   //if data is waiting in buffer...
      {       
         printf("\nCAN KBHIT");
         if(can_getd(rx_id, in_data, rx_len, rxstat)) { //...then get data from buffer
            printf("\nGOT: BUFF=%U ID=%LU LEN=%U OVF=%U ", rxstat.buffer, rx_id, rx_len, rxstat.err_ovfl);
            printf("FILT=%U RTR=%U EXT=%U INV=%U", rxstat.filthit, rxstat.rtr, rxstat.ext, rxstat.inv);
            printf("\n    DATA = ");
            for (i=0;i<rx_len;i++) {
               printf("%X ",in_data[i]);
            }
            printf("\n");
         }
         else {
            printf("\nFAIL on GETD\n");
         }

      }
#endif

#ifdef BOARDTX
       delay_ms(900);
       delay_ms(900);

      if ( 1==1 )
      {
         output_high(BLINKER);
         delay_ms(500);
         output_low(BLINKER);
         
         out_data[0]= 0;  // *** Add these 8 lines
         out_data[1]= 1;
         out_data[2]= 2;
         out_data[3]= 3;
         out_data[4]= 4;
         out_data[5]= 5;
         out_data[6]= 6;
         out_data[7]= 7;
         
         i=can_putd(tx_id, out_data, tx_len,tx_pri,tx_ext,tx_rtr); //put data on transmit buffer
         if (i != 0xFF) { //success, a transmit buffer was open
            delay_ms(200);
            printf("\n PUT %U: ID=%LU LEN=%U ", i, tx_id, tx_len);
            printf("PRI=%U EXT=%U RTR=%U\n   DATA = ", tx_pri, tx_ext, tx_rtr);
            for (i=0;i<tx_len;i++) {
               printf("%X ",out_data[i]);
            }
            printf("\n");
         }
         else { //fail, no transmit buffer was open
            printf("\nFAIL on PUTD\n");
         }
      }
#endif

   }
}


Last edited by defoxe on Tue Feb 10, 2015 3:09 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 30, 2015 10:37 am     Reply with quote

The first thing you should do is get the UART working reliably.
Remove all the CAN code. Just test the UART.

Also post your CCS compiler version. It's given at the top of the .LST file
which is in your project directory after a successful compilation.
defoxe



Joined: 30 Jan 2015
Posts: 8

View user's profile Send private message

PostPosted: Fri Jan 30, 2015 11:20 am     Reply with quote

PCM programmer wrote:
The first thing you should do is get the UART working reliably.
Remove all the CAN code. Just test the UART.


I was trying with simply code for UART. Two different uC and speed 300, 600, 9600.
Its working but I have also crazy signs:

Code:

Iam running �@��@@�I
$�$ � H@� 
RX[H���+��
H� �@ HI��
Iam running
��@��@


PCM programmer wrote:
Also post your CCS compiler version. It's given at the top of the .LST file
which is in your project directory after a successful compilation.


My version is 5.025
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 30, 2015 11:44 am     Reply with quote

Post a small test program only for the UART and I'll test it with your
version. The program should be complete, with #include, #fuses, #use delay, etc.
defoxe



Joined: 30 Jan 2015
Posts: 8

View user's profile Send private message

PostPosted: Sat Jan 31, 2015 11:25 am     Reply with quote

PCM programmer wrote:
Post a small test program only for the UART and I'll test it with your version. The program should be complete, with #include, #fuses, #use delay, etc.


Today I am using my laptop and USB-RS232 converter.
This simple code is working, transmission via UART is clear with no errors.
Also my previous code is working on this adapter.

Code:

#include <18F25K80.h>
#fuses INTRC_IO,NOWDT,PUT,NOPROTECT,NOMCLR,NOCPD,BROWNOUT,NOIESO,NOFCMEN

#use delay(clock=8M)

#use rs232(uart,baud=9600,bits=8,parity=N,stop=1)

void main() {
   delay_ms(300);
   printf("\n\ruC OK\n");
   delay_ms(300);
   
   while(TRUE)
   {
   delay_ms(600);
   printf("\n\rIam running\n");
   delay_ms(600);
   }
}


I was trying to wake up CAN.

#use delay(clock=4M) - nothing special on the oscilloscope
#use delay(clock=8M) and #use delay(clock=64M) - waveforms on an oscilloscope

But no data received and I am not sure if it has been transmitted...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 31, 2015 1:35 pm     Reply with quote

What PIC pins are you using for the CAN bus ? The 18F25K80 can have
the CAN bus on PortB or on PortC, depending upon the #fuses, which
are CANB and CANC. If no fuse is specified, it defaults to PortB.

Try doing the 2-board test with the code that I have posted here.
http://www.ccsinfo.com/forum/viewtopic.php?t=51749&start=13
defoxe



Joined: 30 Jan 2015
Posts: 8

View user's profile Send private message

PostPosted: Tue Feb 03, 2015 1:15 pm     Reply with quote

PCM programmer wrote:
What PIC pins are you using for the CAN bus ? The 18F25K80 can have the CAN bus on PortB or on PortC, depending upon the #fuses, which
are CANB and CANC. If no fuse is specified, it defaults to PortB.


I am using CAN bus on PortB and UART from PortC.

PCM programmer wrote:

Try doing the 2-board test with the code that I have posted here.
http://www.ccsinfo.com/forum/viewtopic.php?t=51749&start=13


My modification:

Code:

#include <18F25k80.h>
#fuses INTRC_IO, NOPROTECT, PUT, BROWNOUT, NOWDT
#use delay(clock=8000000)


And its pretty working!
Thank you for this!
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