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

Can-bus, 18F2580+MCP2551. Loopback ok, real can not working.
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
halibatsuiba



Joined: 12 Aug 2009
Posts: 30

View user's profile Send private message

PostPosted: Sun Sep 27, 2009 10:10 pm     Reply with quote

halibatsuiba wrote:

Debugging continues... Cool


Whadda'y'know...

I could not think of anything else to try so I built another board #2 to a brand new breadboard and...

It works!
I can send characters from terminal over RS232 to board #1, board #1 sends them over CAN bus to board #2 who, in turn, echoes them back to terminal via board #1.
Shocked

[With voice of TV commercial]: "It works, It really works!"

Looks like there is two rows shorted in my old trusted currently-in-the-trashcan breadboard! Embarassed

Thank you, PCM, very much for your help in this issue.
ivrj



Joined: 17 Mar 2009
Posts: 7

View user's profile Send private message

PostPosted: Wed Oct 14, 2009 4:29 pm     Reply with quote

I am also having the same problem.

My board #1 stops on:

Quote:
while(!can_kbhit());


I've modified the source to be easy to debug:
Code:

#include <18F2580.h>
#fuses HS, NOPROTECT, PUT, BROWNOUT, NOWDT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#include <can-18F4580.c>  // Use correct driver

#define BOARD1_ID  24
#define BOARD2_ID  25

// Uncomment this line to compile code for Board #1.
// Comment it out to compile for Board #2.
//#define BOARD1   1   

//======================================
void main()
{
   struct rx_stat rxstat;
   int32 rx_id;
   int32 tx_id;
   int8 rx_len,i;               
   int8 buffer[8];
   
   can_init();
   // starting
   
   for(i = 0; i < 13; i++)
   {
           
            output_toggle(pin_a1);
            delay_ms(90);
            output_toggle(pin_a0);
            output_toggle(pin_a1);
            delay_ms(90);
            output_toggle(pin_a0);
   }
   output_low(pin_a0);
   output_low(pin_a1);
   delay_ms(400);
   #ifdef BOARD1   // For Board #1
   while(1)
   {
      printf("Press a key\r");
      output_high(pin_a0);
      buffer[0] = getc();   // Wait for a character
      printf("lido:%s ", buffer[0]);
      output_low(pin_a0);
      // Transmit it to board #2.
      if(can_putd(BOARD2_ID, buffer, 1, 1, 1, 0))
      {
         printf("Sending a msg\r");
         for(i = 0; i < 6; i++)
         {
            output_toggle(pin_a0);
            delay_ms(100);
           
         }
         output_low(pin_a0);
      }
      else
      {
         printf("Msg sending fail\r");
         for(i = 0; i < 15; i++)
         {
             output_toggle(pin_a0);
             delay_ms(50);
             output_low(pin_a0);
         }
      }
      buffer[0] = 0;   // Clear the buffer byte
   
      // Wait for the char to be echoed back.
      while(!can_kbhit());
   
      if(can_getd(rx_id, buffer, rx_len, rxstat))
      { 
         printf("msg received\r");
         for(i = 0; i < 10; i++)
         {
            output_toggle(pin_a1);
            delay_ms(50);
           
         }
         output_low(pin_a1);
         if(rx_id == BOARD1_ID)  // Is it for this board ?
         {
            for(i = 0; i < 15; i++)
            {
               output_toggle(pin_a1);
               delay_ms(50);
               
            }
            output_low(pin_a1);
            printf("msg:" );
            putc(buffer[0]);  // If so, display the char
         }
      }
   }
#else  // For Board #2
   while(1)
   {
      if(can_kbhit())  // Message available ?
      {
         for(i = 0; i < 6; i++)  // blink a received led
            {
               output_toggle(pin_a0);
               delay_ms(100);
               
            }
            output_low(pin_a0);
         // If so, get the message.
         if(can_getd(rx_id, buffer, rx_len, rxstat))
         {
           
            if(rx_id == BOARD2_ID)  // Is it for this board ?
            {
               for(i = 0; i < 14; i++)  // blink a received led
               {
                  output_toggle(pin_a0);
                  delay_ms(50);
                 
               }
               output_low(pin_a0);
               // If so, echo back the character.
               can_putd(BOARD1_ID, buffer, 1, 1, 1, 0);
            }
          }
       }
   }
#endif
 
}


I just changed the oscilator from 20mhz to 4mhz.


I still have some doubts on the circuit, can somebody post the real circuit schematic?

Just to show my circuit:

is something wrong with him?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 14, 2009 5:18 pm     Reply with quote

It worked for me. I changed the software in the 18F2580 test code,
http://www.ccsinfo.com/forum/viewtopic.php?t=40202&start=22
so that the #use delay() was 4 MHz instead of 20 MHz.

Check your connections and make sure you compiled the software
separately for board #1 and board #2. Make sure you know how
to do that. Make sure your RS232 cable is connected to board #1.
ivrj



Joined: 17 Mar 2009
Posts: 7

View user's profile Send private message

PostPosted: Thu Oct 15, 2009 8:09 am     Reply with quote

PCM programmer wrote:
It worked for me. I changed the software in the 18F2580 test code,
http://www.ccsinfo.com/forum/viewtopic.php?t=40202&start=22
so that the #use delay() was 4 MHz instead of 20 MHz.

Check your connections and make sure you compiled the software
separately for board #1 and board #2. Make sure you know how
to do that. Make sure your RS232 cable is connected to board #1.



I get other 2 20mhz crystal, changed back to the original code and changed delay to 20000000, but isn't working.

PCM programmer wrote:
Does your schematic represent real hardware ? Because, there is no
MCLR circuit. There are no 100 nF ceramic caps on the Vdd pins on any
chip. Also, I would jumper the Rs pins on the MCP2551 chips to ground
for the inital tests.


where I connect the 100nF ceramic capacitors?
ivrj



Joined: 17 Mar 2009
Posts: 7

View user's profile Send private message

PostPosted: Thu Oct 15, 2009 8:19 am     Reply with quote

Error found!

I crossed the can-l can-h lines!

now it´s working fine!

Thank u PCM!!!!
takyonxxx



Joined: 11 Mar 2011
Posts: 1

View user's profile Send private message

MCP2551 ISIS LIBRARY
PostPosted: Fri Mar 11, 2011 7:47 am     Reply with quote

HELLO..
I NEED MCP2551 ISIS LIBRARY, I SAW FROM THE PICTURE THAT YOU USE IT ON PROTEUS. PLEASE I NEED IT. MAY YOU SEND IT TO ME?
OR GIVE ME A LINK.
THANKS...
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, 3
Page 3 of 3

 
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