• AVR Freaks

Helpful ReplyHot!CAN bus on MPLAB Harmony

Author
m_snaeem@hotmail.com
Junior Member
  • Total Posts : 105
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
2020/10/26 06:51:25 (permalink)
0

CAN bus on MPLAB Harmony

Hello,

I want to use the CAN bus using PIC32MX795F512H on MPLAB Harmony. I have a Configure CAN bus in MPLAB Harmony. The setting of the CAN bus is attached to this post. I have written a simple code to transmit a buffer continuously.
But I am not getting anything on CANH and CANL or on CANtx or CANRx side. Instead, i am getting high 3.3V on the input side or output side of the transceiver. My code is given below, Can anybody point out where I am committing a mistake?
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void APP_CAN_Callback(uintptr_t context) {
xferContext = context;
 
/* Check CAN Status */
bool status = CAN1_ErrorGet();
 
if ((status & (CAN_ERROR_TX_RX_WARNING_STATE | CAN_ERROR_RX_WARNING_STATE |
CAN_ERROR_TX_WARNING_STATE | CAN_ERROR_RX_BUS_PASSIVE_STATE |
CAN_ERROR_TX_BUS_PASSIVE_STATE | CAN_ERROR_TX_BUS_OFF_STATE)) == CAN_ERROR_NONE) {
switch ((APP_STATES) context) {
case APP_STATE_CAN_RECEIVE:
case APP_STATE_CAN_TRANSMIT:
{
state = APP_STATE_CAN_XFER_SUCCESSFUL;
break;
}
default:
break;
}
} else {
state = APP_STATE_CAN_XFER_ERROR;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
while(1)
{
CAN1_CallbackRegister(APP_CAN_Callback, (uintptr_t) APP_STATE_CAN_TRANSMIT, 0);
state = APP_STATE_CAN_IDLE;
CAN1_MessageTransmit(messageID, messageLength, tx_message, 0, CAN_MSG_TX_DATA_FRAME);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
post edited by m_snaeem@hotmail.com - 2020/10/26 07:08:45

Attached Image(s)

#1
m_snaeem@hotmail.com
Junior Member
  • Total Posts : 105
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: CAN bus on MPLAB Harmony 2020/10/27 08:37:39 (permalink)
0
I have check data transmission status to become true using CAN1_MessageTransmit() function. and transmit FIFO to get full. but I could not get any waveform on oscilloscope??? Does anybody have an idea how to troubleshoot???
#2
NKurzman
A Guy on the Net
  • Total Posts : 19023
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: CAN bus on MPLAB Harmony 2020/10/27 09:08:08 (permalink)
3 (2)
Are there at least two nodes on the CAN Bus?  one will not work.
#3
m_snaeem@hotmail.com
Junior Member
  • Total Posts : 105
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: CAN bus on MPLAB Harmony 2020/10/27 09:29:09 (permalink)
0
Yes there is 2nd node which receive the data but ctx,CANH and CANL pins are high always no data is displayed on oscilloscope.
#4
m_snaeem@hotmail.com
Junior Member
  • Total Posts : 105
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: CAN bus on MPLAB Harmony 2020/10/28 04:58:01 (permalink)
0
I have one side adm3050  transceiver which is can fd transceiver and on another side mcp2542 transceiver. Could this create a problem in communication?
even C1RX and C1TX don't have any waveform.
Can somebody help???
#5
m_snaeem@hotmail.com
Junior Member
  • Total Posts : 105
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: CAN bus on MPLAB Harmony 2020/10/29 02:27:15 (permalink)
0
I have tx fifo buffer of length 16. upon 1st transmit i got no error but later i get unknown error for 4 to 5 transmit request which code is 150000. and then i got bus off error of code 0x200000.
and after 16th transmit request i get error zero and ISR is called and the cycle is repeated. but still there is no waveform.
Have anybody idea where could be the error??? 
#6
m_snaeem@hotmail.com
Junior Member
  • Total Posts : 105
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: CAN bus on MPLAB Harmony 2020/10/29 05:46:01 (permalink)
0
CANTX pin Goes low now and upon reset only get waveform like this:
Can anybody help??
post edited by m_snaeem@hotmail.com - 2020/10/29 05:47:33

Attached Image(s)

#7
m_snaeem@hotmail.com
Junior Member
  • Total Posts : 105
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: CAN bus on MPLAB Harmony 2020/10/30 06:31:08 (permalink)
5 (1)
Can anybody have idea what does AC1TX or AC1RX means???
Is it acknowledgement or something else??
and do we need to use it for CAN configuration???
 
Edit
got it it is alternative CAN Pin
post edited by m_snaeem@hotmail.com - 2020/10/30 06:38:23

Attached Image(s)

#8
karan123
Super Member
  • Total Posts : 1029
  • Reward points : 0
  • Joined: 2009/02/02 11:11:21
  • Location: 0
  • Status: offline
Re: CAN bus on MPLAB Harmony 2020/10/31 22:43:44 (permalink) ☄ Helpfulby m_snaeem@hotmail.com 2020/11/01 05:39:00
0
AC1TX and AC1RX are alternative pins that can assigned for CAN1 (instead of C1TX and C1RX)
With Configuration Bits.
#9
m_snaeem@hotmail.com
Junior Member
  • Total Posts : 105
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: CAN bus on MPLAB Harmony 2020/11/01 05:42:48 (permalink)
0
Thanks karan123.
but my problem did not solved even i have used microchip sample code from website

https://microchip-mplab-harmony.github.io/csp/frames.html?frmname=topic&frmfile=07022.html
 
I could not receive the data through the transmitter sends the data successfully but no C1TX waveform on the oscilloscope. 
#10
m_snaeem@hotmail.com
Junior Member
  • Total Posts : 105
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: CAN bus on MPLAB Harmony 2020/11/02 03:35:22 (permalink)
0
The problem is solved. I could not be able to communicate two microcontroller using CAN bus using C1RX and C1TX but using AC1RX and AC1TX  pins dont know why........! 
I can receive and transmit messages using CAN bus
#11
karan123
Super Member
  • Total Posts : 1029
  • Reward points : 0
  • Joined: 2009/02/02 11:11:21
  • Location: 0
  • Status: offline
Re: CAN bus on MPLAB Harmony 2020/11/02 03:41:09 (permalink)
4 (1)
I think you should check configuration bits associate with AC1TX and AC1RX in the demo that you have used or it's default setting.
#12
m_snaeem@hotmail.com
Junior Member
  • Total Posts : 105
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: CAN bus on MPLAB Harmony 2020/11/02 03:48:59 (permalink)
2 (1)
I was using C1TX and C1RX bits assigned with Microchip harmony Configurator but it did not give TX signal. I have assigned AC1TX and AC1RX pins to can module and they worked.
In demo i dont have assigned any Pins but in MHC.
Can you elaborate on how to check?


#13
m_snaeem@hotmail.com
Junior Member
  • Total Posts : 105
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: CAN bus on MPLAB Harmony 2020/11/02 04:22:29 (permalink)
2 (1)
Karan123 you are right.
the configuration bit for CAN bus is set for alternate CAN IO.
Do you know where to add code generated by configuration bits in case of MHC???
#14
m_snaeem@hotmail.com
Junior Member
  • Total Posts : 105
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: CAN bus on MPLAB Harmony 2020/11/02 04:39:48 (permalink)
0
I have copied Generated source code(configuartion bit) to the project but mplap does not compile it.
Does anybody have idea where to set configuation bit in other case??
#15
m_snaeem@hotmail.com
Junior Member
  • Total Posts : 105
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: CAN bus on MPLAB Harmony 2020/11/02 05:23:35 (permalink)
0
I got it.
In MHC -> System -> DEVCFG3 -> FCANIO -> ON


#16
karan123
Super Member
  • Total Posts : 1029
  • Reward points : 0
  • Joined: 2009/02/02 11:11:21
  • Location: 0
  • Status: offline
Re: CAN bus on MPLAB Harmony 2020/11/02 06:44:35 (permalink)
5 (1)
m_snaeem@hotmail.com
I got it.
In MHC -> System -> DEVCFG3 -> FCANIO -> ON



Good...
#17
Jump to:
© 2020 APG vNext Commercial Version 4.5