|
Thanks for your advices and I am sorry because I am confused where to post my question since the source code is in .c file type so I am thought i can post it in C++.
It would be great if u can gives me some link to some example of CAN using PIC since I can't really find one that I manage to understood.
|
|
|
|
|
use either the hardware forum or the C/C++ forum. I will probably see it where ever you put it!
search for:
PIC application notes
PIC AN738
TCanDriver
16F876 CAN source code
if you need more help, ask specific questions; however begin with providing detailed context: are you using a kernel/operating system? do you need to interact with existing CAN nodes? if so, what specific CAN protocol do you need? what is the application? what is the bit rate, the bus load to be expected, the rate of *other* interrupts, etc etc.
Embedded systems aren't simple. If this were your first experiment, start with simpler things: a few LEDs (needed anyway for debugging), a serial port. When you feel comfortable, switch to more complex stuff (such as USB, Ethernet, CAN).
End of thread.
|
|
|
|
|
yea, this is the first time I experiment with CAN. I was confuse where to start with. I have already collected and roughly go through the data sheet for each PIC needed. After that, I drawn the circuit diagram and then tried to understand the source code I posted above but its too complicated for a beginner like me.
I really appreciated your prompt reply. I think i should make myself more clear before I ask questions.
Thanks again for your prompt reply. Hope to receive your reply for my future question.
|
|
|
|
|
Hi Luc Pattyn,
Do you used simulation to run your CAN project? If yes, may I know what is the simulator? I have a proteus 7 software which can do simulation job, but the problem is the software dont have MCP 2551 and MCP 2515 device. I cant find the library.
I have done a simple program but it does not run when i burn into the microcontroller (pic 16f877). There is no compilation error also.
CAN node 1
unsigned char Can_Init_Flags, Can_Send_Flags, Can_Rcv_Flags;
unsigned char Rx_Data_Len;
char RxTx_Data[8];
char Msg_Rcvd;
const long ID_1st = 12111, ID_2nd = 3;
long Rx_ID;
sbit CanSpi_CS at RC0_bit;
sbit CanSpi_CS_Direction at TRISC0_bit;
sbit CanSpi_Rst at RC2_bit;
sbit CanSpi_Rst_Direction at TRISC2_bit;
void main() {
PORTA = 0x00;
TRISA = 0xFF;
PORTD = 0x00;
TRISD = 0x00;
Can_Init_Flags = 0;
Can_Send_Flags = 0;
Can_Rcv_Flags = 0;
Can_Send_Flags = _CANSPI_TX_PRIORITY_0 &
_CANSPI_TX_XTD_FRAME &
_CANSPI_TX_NO_RTR_FRAME;
Can_Init_Flags = _CANSPI_CONFIG_SAMPLE_THRICE &
_CANSPI_CONFIG_PHSEG2_PRG_ON &
_CANSPI_CONFIG_XTD_MSG &
_CANSPI_CONFIG_DBL_BUFFER_ON &
_CANSPI_CONFIG_VALID_XTD_MSG;
SPI1_Init();
CANSPIInitialize(1,3,3,3,1,Can_Init_Flags);
CANSPISetOperationMode(_CANSPI_MODE_CONFIG,0xFF);
CANSPISetMask(_CANSPI_MASK_B1,-1,_CANSPI_CONFIG_XTD_MSG);
CANSPISetMask(_CANSPI_MASK_B2,-1,_CANSPI_CONFIG_XTD_MSG);
CANSPISetFilter(_CANSPI_FILTER_B2_F4,ID_2nd,_CANSPI_CONFIG_XTD_MSG);
CANSPISetOperationMode(_CANSPI_MODE_NORMAL,0xFF);
RxTx_Data[0] = 9;
CANSPIWrite(ID_1st, RxTx_Data, 1, Can_Send_Flags);
}
CAN node2
unsigned char Can_Init_Flags, Can_Send_Flags, Can_Rcv_Flags;
unsigned char Rx_Data_Len;
char RxTx_Data[8];
char Msg_Rcvd;
const long ID_1st = 12111, ID_2nd = 3;
long Rx_ID;
sbit CanSpi_CS at RC0_bit;
sbit CanSpi_CS_Direction at TRISC0_bit;
sbit CanSpi_Rst at RC2_bit;
sbit CanSpi_Rst_Direction at TRISC2_bit;
void main() {
PORTA = 0x00;
TRISA = 0x00;
PORTD = 0x00;
TRISD = 0x00;
Can_Init_Flags = 0;
Can_Send_Flags = 0;
Can_Rcv_Flags = 0;
Can_Send_Flags = _CANSPI_TX_PRIORITY_0 &
_CANSPI_TX_XTD_FRAME &
_CANSPI_TX_NO_RTR_FRAME;
Can_Init_Flags = _CANSPI_CONFIG_SAMPLE_THRICE &
_CANSPI_CONFIG_PHSEG2_PRG_ON &
_CANSPI_CONFIG_XTD_MSG &
_CANSPI_CONFIG_DBL_BUFFER_ON &
_CANSPI_CONFIG_VALID_XTD_MSG &
_CANSPI_CONFIG_LINE_FILTER_OFF;
SPI1_Init();
CANSPIInitialize(1,3,3,3,1,Can_Init_Flags);
CANSPISetOperationMode(_CANSPI_MODE_CONFIG,0xFF);
CANSPISetMask(_CANSPI_MASK_B1,-1,_CANSPI_CONFIG_XTD_MSG);
CANSPISetMask(_CANSPI_MASK_B2,-1,_CANSPI_CONFIG_XTD_MSG);
CANSPISetFilter(_CANSPI_FILTER_B2_F3,ID_1st,_CANSPI_CONFIG_XTD_MSG);
CANSPISetOperationMode(_CANSPI_MODE_NORMAL,0xFF);
Msg_Rcvd = CANSPIRead(&Rx_ID , RxTx_Data , &Rx_Data_Len, &Can_Rcv_Flags);
if ((Rx_ID == ID_1st) && Msg_Rcvd) {
PORTD = 0x01;
}
else
PORTD = 0x08;
}
The result is 0000 1000, which means node 2 does not received any message from node 1.
I hope you can advise me in this problem. Thanks.
|
|
|
|
|
No, we never used simulation for CAN. I am also unfamiliar with CANSPI library, we used our own code, directly accessing the hardware.
Some thoughts:
1.
If the first node sends before the second got through initialization, the message would be lost. Having both nodes powered by the same supply (just a guess), and/or even connected to the same reset line, would still leave a timing uncertainty on which starts up first, and how big the launch time difference would be (tens of msec easily).
2.
is CANSPIRead() a blocking function? and would it work right after initialization?
Suggestion: I would make one node send one message per second, say an incrementing number; then see of the second node gets anything at all.
|
|
|
|
|
Hi,
Hmm, so you are suggesting that I should have several lines of CANSPIWrite()?
There are many things that I still not sure....I just experiment with it.
However, thanks a lot for your prompt reply.
regards,
kent
|
|
|
|
|
Hi Luc Pattyn,
I have one favor to ask. Can you take a look on my system diagram? I want to make sure that my connection is ok. However, I don't know how to upload the image on this forum. I can email my system diagram to you, if you are fine with it.
Thanks.
Regards,
Kent
|
|
|
|
|
You need some Gold or Platinum reputation around here to get upload capabilities.
However you could upload to some public service (such as Flickr), then post the link here.
BTW: You are totally abusing this forum, even more than when you started this thread.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
|
I haven't checked the diagram against the datasheets or application notes from the manufacturer, you should if you haven't already. There aren't many ways to connect things up anyway.
kent5244 wrote: Abusing the forum?
I suggest you read again the very first sentence I've replied in this thread.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
May I know how to convert SAFEARRAY to System::Object,
error C2664: void .....(System::String ^,System::Object ^)' : cannot convert parameter 2 from 'SAFEARRAY *' to 'System::Object ^'
thanks
|
|
|
|
|
|
Hi,
I m new to CLI ,
Can anyone tell me How to use C DLL in C++/CLI???
Thanks,
Sachin
|
|
|
|
|
|
how to convert tchar to lpcwstr
|
|
|
|
|
TCHAR is single unit, LPCWSTR would be set of units.
See this[^]
|
|
|
|
|
Dear Friends
I am facing some problems in deploying my application for lower version of qt.
Basically i want to generate scripts for my application and I have chosen pythonqt for this purpose. Pythonqt has the problem with lower version of Qt (Qt 4.5.2) and also with Higher version of Qt (Qt 4.7). So I needed to get another machine where I have installed Qt-4.6.3 with in-built python version 2.6. I am successfully able to generate my application exe and it is running.
But the requirement is that this exe should run on my original machine so I built the application with the static link of Qt4.6.3-static.
My original machine has python2.3 installed.
But I am not able run on original machine. Its giving 3 library linking problem. as below
libpng14.so.14 => not found
libEGL.so.1 => not found
libpython2.6.so.1.0 => not found
I have libpng12 installed in original system......I am keeping the libong14 from my new machine in a local lib folder and exporting LD_LIBRARY_PATH to/the/local/lib but still its not able to find the libpng14
similarly for libpython2.6 I am keeping the libpython2.6 from new machine into the local lib folder. but its not recognizing.
libEGL i dont even know.
Please give me some suggesstions what can be done.
Thanks sujan
|
|
|
|
|
And what does this have to do with "Managed C++/CLI"?
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
using namespace System::Runtime::InteropServices;
public ref class CTest
{
public:
static delegate bool Callback(int i);
}
While compliting I get error.
error C2144: syntax error : 'bool' should be preceded by ';'
I would like to use delegate as a callback function and select one of the serval avaliable function.
Please advice. thanks.
|
|
|
|
|
Remove the 'static' keyword - it's the cause of the error (and add a semi-colon after the class closing brace).
David Anton
Convert between VB, C#, C++, & Java
www.tangiblesoftwaresolutions.com
|
|
|
|
|
Thanks a lot it worked.
Basically I need an advice. I am woking in dot net managed C++ . I had a very large switch statement with about 50 cases
now I am refactoring the switch case. putting each case in a function and using a delagate as callback and
main ()
{
switch (ivar)
{
case 1:
{
break;
}
case 1:
{
break;
}
so on
case 50:
{
break
}
}
}
And now I am writing function
void somecode1(int a, int b)
{
somecode 1;
}
void somecode2(int a, int b)
{
somecode 2;
}
void somecode3(int a, int b)
{
somecode 50;
}
static void Parse(int iType)
{
FunList entry = m_FunList[iType];
entry.m_Callback.Invoke();
}
static void Main(string[] args)
{
Init();
i=7
Parse(i);
}
static void Init()
{
}
Can you please correct me if I am doing some thing not correct?
Is there any pattern that suits better?
Thanks
modified on Wednesday, November 24, 2010 11:21 PM
|
|
|
|
|
Folks..
I have created a wrapper project that exports two procedures that I pick up in my Win32 program created in something called Clarion for Windows. The wrapper class calls my C# objects and this works just fine. Problem is that my C# program neads different calls back to my Clarion Win32 program. For instance, my Win32 program has a function to generate new Customer ID's and the complexity of this routine is to much. Becides, I would really like to know if there is a way to do this. The connection between Clarion Win32 and C++ is by using a standard interface decleared in Clarion and passed into the exported function in C++. Problem is that I dont know how to call back to C++
Hers what I have:
Clarion(Win32) <=> C++ => C#
So Clarion can call C++ methods directly through the Interface, and therfor implicit Clarion can call .NET methods through this wrapper. But I nead the other way too.
I was hoping I could pass an Interface from C++ into my C# objects, maybe something like this:
MyNetClass::TakeCppInterface(ThisCppInterface);
I have posted on the MSDN, but only answer I got there was using MSIL or reflection, which i think is way over my head at the moment.
-----------------------------
Speaking nordic language?
Why not visiting irc.c-c.no and join #C# or #VisualBasic
-----------------------------
|
|
|
|
|
You can use a C++/CLI wrapper instead of C++ wrapper so that C++/CLI wrapper can use directly in C#
|
|
|
|
|
Well, isnt that what I allready do
I nead to call back to C++ from the C#
Her's the flow:
Clarion(Win32) Calls C++ method.
C++ then calls C# method.
C# Method calls C++ Method.
C++ Method Calls Clarion(Win32) Method
now, Clarion and C++ can comunisafe over an Interface
C++ and C# communicates through a class
But what can I use to communicate C# to C++ ?
-----------------------------
Speaking nordic language?
Why not visiting irc.c-c.no and join #C# or #VisualBasic
-----------------------------
|
|
|
|
|
can you provide a code snippet
|
|
|
|
|