|
|
View previous topic :: View next topic |
Author |
Message |
halibatsuiba
Joined: 12 Aug 2009 Posts: 30
|
|
Posted: Sun Sep 27, 2009 10:10 pm |
|
|
halibatsuiba wrote: |
Debugging continues... |
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.
[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!
Thank you, PCM, very much for your help in this issue. |
|
|
ivrj
Joined: 17 Mar 2009 Posts: 7
|
|
Posted: Wed Oct 14, 2009 4:29 pm |
|
|
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
|
|
Posted: Wed Oct 14, 2009 5:18 pm |
|
|
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
|
|
Posted: Thu Oct 15, 2009 8:09 am |
|
|
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
|
|
Posted: Thu Oct 15, 2009 8:19 am |
|
|
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
|
MCP2551 ISIS LIBRARY |
Posted: Fri Mar 11, 2011 7:47 am |
|
|
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... |
|
|
|
|
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
|