Hello, I am trying to use the can shield to communicate with a sensor (Trafag 8270) software manual available by searching for:
</s>trafag pressure transmitter 8270 operating instructions software<e>
How do I read from the sensor. having established that the sensor is setup to CAN_20KBS.
I cannot seem to set the RTR bit which I am under the impression I need to request data.
As far as I understand, i have broken this down into several smaller questions.
</s><i>
</i>/*********************************************************************************************************
** Function name: sendMsgBuf
** Descriptions: send buf
*********************************************************************************************************/
INT8U MCP_CAN::sendMsgBuf(INT32U id, INT8U ext, INT8U len, INT8U *buf)
{
setMsg(id, ext, len, buf);
sendMsg();
}<e>
- is id the can-id or the COB-ID?
- how do I send NMT packets (to initialize the sensor)
2)
my source code:
[code]#include “main.h”
// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_CAN = 17;
const int SPI_CS_SD = 5;
//MCP_CAN CAN(SPI_CS_CAN); // Set CS pin
unsigned char flagRecv = 0;
unsigned char len = 0;
unsigned char buf[8];
char str[20];
void MCP2515_ISR();
uint32_t generateCOB_ID(uint8_t nodeID, uint16_t functionCode){
return (functionCode|nodeID);
}
void setup()
{
Serial.begin(115200);
while (CAN_FAILINIT == CAN.begin(CAN_RATE)); // init can bus : baudrate = 500k
{
Serial.println("CAN BUS Shield init fail");
Serial.println("Init CAN BUS Shield again");
delay(1000);
}
Serial.println("CAN BUS Shield init ok!");
}
void MCP2515_ISR()
{
flagRecv = 1;
}
void loop()
{
Serial.print("ERROR : ");
Serial.println(CAN.checkError());
Serial.print("Status : ");
Serial.println(CAN.checkReceive());
Serial.print("ID : ");
Serial.println(CAN.getCanId());
if(CAN_MSGAVAIL == CAN.checkReceive())
{ // check if get data
unsigned long id= 0;
while (CAN_MSGAVAIL == CAN.checkReceive())
{
// read data, len: data length, buf: data buf
CAN.readMsgBuf( &len, buf);
id = CAN.getCanId();
Serial.print(id);
Serial.print(",");
for(int i = 0; i<len; i++)
{
Serial.print(buf[i]);
Serial.print(",");
}
Serial.println();
}
}
}
[/code]
output (repeatedly):
</s>ERROR : 0
Status : 4
ID : 74<e>