Hello,
Please help me to solve the puzzle with CAN Bus implementation under Apalis T30. It does not work at all.
I use it with WEC2013 and implementing my code using C#
I am also using latest available library for CAN/GPIO etc. TdxAllLibraries.dll and TdxAllLibraries.cs files both available and attached to project.
What I have done:
Apalis T30
Custom carrier board
Everything connected. WEC2013 running. Able to deploy and run code from VS2015
What I do:
Apalis T30 does not have native CAN controllers. Instead two MPC2515 installed on Apalis PCB and connected via SPI to main chip.
We assume that we need to initialize CAN as SPI1 or SPI2.
My code:
//Assign variable
bool result = false;
uint res = 0;
IntPtr CAN_handle = new IntPtr(0);
gpio.uIo _canRx = new gpio.uIo((ushort)12, (ushort)gpio.tIoType.ioApalisPin);
gpio.uIo _canTx = new gpio.uIo((ushort)14, (ushort)gpio.tIoType.ioApalisPin);
//gpio.uIo _canIntrp = new gpio.uIo((ushort)19, (ushort)gpio.tIoType.ioApalisPin);
IntPtr _gpio;
_gpio = gpio.Gpio_Init(null);
if (_gpio == null)
{
Debug.WriteLine("GPIO Init Failed");
}
if (!gpio.Gpio_Open(_gpio))
{
Debug.WriteLine("GPIO Open Failed");
}
//Initialize CAN bus
CAN_handle = can_teg.TegCan_Init("SPI1");
if (CAN_handle == null)
Debug.WriteLine("Error. No CAN Handle");
can_teg.TegCan_SetConfigInt(CAN_handle, "ioRx", _canRx.GenericDefinition, TdxCommon.ParamStorageType.StoreToRegistry);
can_teg.TegCan_SetConfigInt(CAN_handle, "ioTx", _canTx.GenericDefinition, TdxCommon.ParamStorageType.StoreToRegistry);
can_teg.TegCan_SetConfigInt(CAN_handle, "BitRateHz", 100000, TdxCommon.ParamStorageType.StoreVolatile);
can_teg.TegCan_SetConfigInt(CAN_handle, "FilterID", 0x00, TdxCommon.ParamStorageType.StoreVolatile);
can_teg.TegCan_SetConfigInt(CAN_handle, "FilterMask", 0x00, TdxCommon.ParamStorageType.StoreVolatile);
can_teg.TegCan_SetConfigString(CAN_handle, "FilterFrameFormat", "None", TdxCommon.ParamStorageType.StoreVolatile);
can_teg.TegCan_SetConfigString(CAN_handle, "FilterRemote", "none", TdxCommon.ParamStorageType.StoreVolatile);
//can_teg.TegCan_SetConfigInt(CAN_handle, "ioInterrupt", _canIntrp.GenericDefinition, TdxCommon.ParamStorageType.StoreVolatile);
//can_teg.TegCan_SetConfigInt(CAN_handle, "IstPriority", 0x10, TdxCommon.ParamStorageType.StoreVolatile);
can_teg.TegCan_SetConfigInt(CAN_handle, "Timeout", 1000, TdxCommon.ParamStorageType.StoreVolatile);
//Open CAN line
result = can_teg.TegCan_Open(CAN_handle);
Debug.WriteLine("CAN Init Result: " + result.ToString());
uint result2 = can_teg.TegCan_GetConfigInt(CAN_handle, "BusStatus", ref res);
Debug.WriteLine("Bus status: " + res.ToString());
StringBuilder sb = new StringBuilder("", 50);
can_teg.TegCan_GetConfigString(CAN_handle, "Implementation", sb, 20);
Debug.WriteLine("Bus implementation: " + sb.ToString());
My problem:
I am able to get CAN Handle for SPI1 CAN using initial command to CAN_Init(SPI1)
At this point handle is available.
Next I am configuring my CAN as per Toradex help file for CAN library. I am setting all parameters required for configuration prior calling CAN_Open.
Next I am calling CAN_Open and always getting FALSE. I can not get CAN_Open to return TRUE despite trying everything possible.
With the same time I am getting BusStatus as: ‘2’ - which means No transmission or receipt of messages is possible. Finally I am getting Implementation as ‘Mcp2515’ which is correct and according to expectations.
Toradex support! Please help with this. It is unbelievable that CAN bus is not supported on this board.
Your CAN_Demo.c which I have and use as reference is poorly written. Especially configuration part.
I downloaded this sample CAN_Demo.c from your website just yesterday. It is likely latest version but it has all config block as ‘//’ and I have no idea if I need to use all config variables which I send or not.
I tried all possible combinations but always! getting FALSE on CAN Open.
Obviously I was not able to move forward on that since CAN_Open is initial command which needs to be passed.
Thanks,
Vlad