dakujem za pomoc.odkomentoval som vsetko podla vasich rad v SpiTransfer.h aj SpiTransfer.cpp
tu su nahlady :
Kód: Vybrat vše
#pragma once
#include "Arduino.h"
#if not(defined(MBED_H) || defined(__SAM3X8E__)) // These boards are/will not be supported by SPITransfer.h
#include "Packet.h"
#include "SPI.h"
class SPITransfer
{
public: // <<---------------------------------------//public
Packet packet;
uint8_t bytesRead = 0;
int8_t status = 0;
void begin(SPIClass& _port, const configST configs, const uint8_t& _SS = SS);
void begin(SPIClass& _port, const uint8_t& _SS = SS, const bool _debug = true, Stream& _debugPort = Serial);
uint8_t sendData(const uint16_t& messageLen, const uint8_t packetID = 0);
uint8_t available();
uint8_t currentPacketID();
/*
uint16_t SPITransfer::txObj(const T &val, const uint16_t &index=0, const uint16_t &len=sizeof(T))
Description:
------------
* Stuffs "len" number of bytes of an arbitrary object (byte, int,
float, double, struct, etc...) into the transmit buffer (txBuff)
starting at the index as specified by the argument "index"
Inputs:
-------
* const T &val - Pointer to the object to be copied to the
transmit buffer (txBuff)
* const uint16_t &index - Starting index of the object within the
transmit buffer (txBuff)
* const uint16_t &len - Number of bytes of the object "val" to transmit
Return:
-------
* uint16_t maxIndex - uint16_t maxIndex - Index of the transmit buffer (txBuff) that directly follows the bytes processed
by the calling of this member function
*/
template <typename T>
uint16_t txObj(const T& val, const uint16_t& index = 0, const uint16_t& len = sizeof(T))
{
return packet.txObj(val, index, len);
}
/*
uint16_t SPITransfer::rxObj(const T &val, const uint16_t &index=0, const uint16_t &len=sizeof(T))
Description:
------------
* Reads "len" number of bytes from the receive buffer (rxBuff)
starting at the index as specified by the argument "index"
into an arbitrary object (byte, int, float, double, struct, etc...)
Inputs:
-------
* const T &val - Pointer to the object to be copied into from the
receive buffer (rxBuff)
* const uint16_t &index - Starting index of the object within the
receive buffer (rxBuff)
* const uint16_t &len - Number of bytes in the object "val" received
Return:
-------
* uint16_t maxIndex - Index of the receive buffer (rxBuff) that directly follows the bytes processed
by the calling of this member function
*/
template <typename T>
uint16_t rxObj(const T& val, const uint16_t& index = 0, const uint16_t& len = sizeof(T))
{
return packet.rxObj(val, index, len);
}
/*
uint8_t SPITransfer::sendDatum(const T &val, const uint16_t &len=sizeof(T))
Description:
------------
* Stuffs "len" number of bytes of an arbitrary object (byte, int,
float, double, struct, etc...) into the transmit buffer (txBuff)
starting at the index as specified by the argument "index" and
automatically transmits the bytes in an individual packet
Inputs:
-------
* const T &val - Pointer to the object to be copied to the
transmit buffer (txBuff)
* const uint16_t &len - Number of bytes of the object "val" to transmit
Return:
-------
* uint8_t - Number of payload bytes included in packet
*/
template <typename T>
uint8_t sendDatum(const T& val, const uint16_t& len = sizeof(T))
{
return sendData(packet.txObj(val, 0, len));
}
private: // <<---------------------------------------//private
SPIClass* port;
uint8_t ssPin;
};
#endif // not (defined(MBED_H) || defined(__SAM3X8E__))
Kód: Vybrat vše
#include "Arduino.h"
#if not(defined(MBED_H) || defined(__SAM3X8E__) || defined(DISABLE_SPI_SERIALTRANSFER)) // These boards are/will not be supported by SPITransfer.h
#include "SPITransfer.h"
/*
void SPITransfer::begin(SPIClass &_port, configST configs, const uint8_t &_SS)
Description:
------------
* Advanced initializer for the SPITransfer Class
Inputs:
-------
* const SPIClass &_port - SPI port to communicate over
* const configST configs - Struct that holds config
* const uint8_t &_SS - SPI buslave select pin used
values for all possible initialization parameters
Return:
-------
* void
*/
void SPITransfer::begin(SPIClass& _port, const configST configs, const uint8_t& _SS)
{
port = &_port;
packet.begin(configs);
ssPin = _SS;
}
/*
void SPITransfer::begin(SPIClass &_port, const uint8_t &_SS, const bool _debug, Stream &_debugPort)
Description:
------------
* Simple initializer for the SPITransfer Class
Inputs:
-------
* const Stream &_port - SPI port to communicate over
* const uint8_t &_SS - SPI buslave select pin used
* const bool _debug - Whether or not to print error messages
* const Stream &_debugPort - Serial port to print error messages
Return:
-------
* void
*/
void SPITransfer::begin(SPIClass& _port, const uint8_t& _SS, const bool _debug, Stream& _debugPort)
{
port = &_port;
packet.begin(_debug, _debugPort);
ssPin = _SS;
}
/*
uint8_t SPITransfer::sendData(const uint16_t &messageLen, const uint8_t packetID)
Description:
------------
* Send a specified number of bytes in packetized form
Inputs:
-------
* const uint16_t &messageLen - Number of values in txBuff
to send as the payload in the next packet
* const uint8_t packetID - The packet 8-bit identifier
Return:
-------
* uint8_t numBytesIncl - Number of payload bytes included in packet
*/
uint8_t SPITransfer::sendData(const uint16_t& messageLen, const uint8_t packetID)
{
uint8_t numBytesIncl = packet.constructPacket(messageLen, packetID);
digitalWrite(SS, LOW); // Enable SS (active low)
for (uint8_t i = 0; i < sizeof(packet.preamble); i++)
{
delay(1); // This delay is needed
port->transfer(packet.preamble[i]);
}
for (uint8_t i = 0; i < numBytesIncl; i++)
{
delay(1); // This delay is needed
port->transfer(packet.txBuff[i]);
}
for (uint8_t i = 0; i < sizeof(packet.postamble); i++)
{
delay(1); // This delay is needed
port->transfer(packet.postamble[i]);
}
digitalWrite(SS, HIGH); // Disable SS (active low)
return numBytesIncl;
}
/*
uint8_t SPITransfer::available()
Description:
------------
* Parses incoming serial data, analyzes packet contents,
and reports errors/successful packet reception
Inputs:
-------
* void
Return:
-------
* uint8_t bytesRead - Num bytes in RX buffer
*/
uint8_t SPITransfer::available()
{
volatile uint8_t recChar = SPDR;
bytesRead = packet.parse(recChar);
status = packet.status;
return bytesRead;
}
/*
uint8_t SPITransfer::currentPacketID()
Description:
------------
* Returns the ID of the last parsed packet
Inputs:
-------
* void
Return:
-------
* uint8_t - ID of the last parsed packet
*/
uint8_t SPITransfer::currentPacketID()
{
return packet.currentPacketID();
}
#endif // not (defined(MBED_H) || defined(__SAM3X8E__))
no aj tak mi to vyhadzuje chybove hlasky:
C:\Users\User\Documents\Arduino\libraries\SerialTransfer\src\SPITransfer.cpp: In member function 'uint8_t SPITransfer::available()':
C:\Users\User\Documents\Arduino\libraries\SerialTransfer\src\SPITransfer.cpp:112:49: error: binding reference of type 'const uint8_t& {aka const unsigned char&}' to 'volatile uint8_t {aka volatile unsigned char}' discards qualifiers
bytesRead = packet.parse(recChar);
^
In file included from C:\Users\User\Documents\Arduino\libraries\SerialTransfer\src\SPITransfer.h:7:0,
from C:\Users\User\Documents\Arduino\libraries\SerialTransfer\src\SPITransfer.cpp:5:
C:\Users\User\Documents\Arduino\libraries\SerialTransfer\src\Packet.h:65:10: note: initializing argument 1 of 'uint8_t Packet::parse(const uint8_t&, const bool&)'
uint8_t parse(const uint8_t& recChar, const bool& valid = true);
^~~~~
exit status 1
Nastala chyba pri kompilácii pre dosku Arduino Pro or Pro Mini.