SPI transfer

Odpovědět
minicico1
Příspěvky: 29
Registrován: 30 kvě 2019, 01:13
Reputation: 0

SPI transfer

Příspěvek od minicico1 » 10 bře 2023, 23:01

Ahojte, pouzival som kniznicu z https://github.com/PowerBroker2/SerialTransfer.
konkretne SPI prenos.ten je povodne zakomentovany a treba ho odkomentovat.uz som skusal kadeco odkomentovat v SPITransfer.h a v SPITransfer.cpp, ale stale mi hadze chybove hlasky pri kompilacii. moze ma niekto nakopnut kde robim chybu ja, lebo v starom ntb. mi tato kniznica chodila.

AstroMiK
Příspěvky: 592
Registrován: 08 pro 2017, 19:05
Reputation: 0

Re: SPI transfer

Příspěvek od AstroMiK » 11 bře 2023, 00:14

Na takovýto dotaz ti nikdo odpovědět nemůže.

Pokud tu nechceš zveřejnit celý kód, tak alespoň okopíruj to chybové hlášení a popiš přesně, co jsi odkomentoval v té knihovně.

Máš stejné verze té knihovny na starém a novém počítači?
Funguje alespoň nějaký jednoduchý příklad toho SPItransferu ze složky "Examples"?

minicico1
Příspěvky: 29
Registrován: 30 kvě 2019, 01:13
Reputation: 0

Re: SPI transfer

Příspěvek od minicico1 » 11 bře 2023, 01:49

ospravedlnujem sa,mal som to napisat ze rovnaku hlasku mi vyhadzuje aj pri mojom kode aj pri exaple kode na git.hlavny problem je ze na konci popisu kniznice na git. je poznamka ze SPi komunikacia je default deaktivovana a pre jej fungovanie je treba odkomentovat jeden riadok v SerialTransfer.h. tu je ta poznamka:

SPITransfer.h and it's associated features are not supported for the Arduino Nano 33 BLE or DUE and other boards. This header file is disabled by default, but can be enabled by commenting out #define DISABLE_SPI_SERIALTRANSFER 1 within SerialTransfer.h.

no problem je ze ten riadok v subore vobec nieje.

tuto chybovu hlasku mi vyhodi pri kompilovani:

Kód: Vybrat vše

In file included from C:\Users\User\Documents\Arduino\libraries\SerialTransfer\examples\spi_tx_datum\spi_tx_datum.ino:1:0:
C:\Users\User\Documents\Arduino\libraries\SerialTransfer\src/SPITransfer.h:2:2: error: 'UNCOMMENT' does not name a type
  UNCOMMENT FOR USAGE
  ^~~~~~~~~
In file included from C:\Users\User\Documents\Arduino\libraries\SerialTransfer\src/Packet.h:16:0,
                 from C:\Users\User\Documents\Arduino\libraries\SerialTransfer\src/SPITransfer.h:7,
                 from C:\Users\User\Documents\Arduino\libraries\SerialTransfer\examples\spi_tx_datum\spi_tx_datum.ino:1:
C:\Users\User\Documents\Arduino\libraries\SerialTransfer\src/PacketCRC.h:76:8: error: 'PacketCRC' does not name a type
 extern PacketCRC crc;
        ^~~~~~~~~
spi_tx_datum:4:13: error: field 'myTransfer' has incomplete type 'SPITransfer'
 SPITransfer myTransfer;
             ^~~~~~~~~~
In file included from C:\Users\User\Documents\Arduino\libraries\SerialTransfer\examples\spi_tx_datum\spi_tx_datum.ino:1:0:
C:\Users\User\Documents\Arduino\libraries\SerialTransfer\src/SPITransfer.h:11:7: note: definition of 'class SPITransfer' is not complete until the closing brace
 class SPITransfer
       ^~~~~~~~~~~
spi_tx_datum:12:6: error: 'void SPITransfer::setup()' cannot be overloaded
 void setup()
      ^~~~~
spi_tx_datum:12:6: error: with 'void SPITransfer::setup()'
 void setup()
      ^~~~~
spi_tx_datum:28:6: error: 'void SPITransfer::loop()' cannot be overloaded
 void loop()
      ^~~~
spi_tx_datum:28:6: error: with 'void SPITransfer::loop()'
 void loop()
      ^~~~
spi_tx_datum:32:1: error: expected '}' at end of input
 }
 ^
spi_tx_datum:32:1: error: expected unqualified-id at end of input
exit status 1
field 'myTransfer' has incomplete type 'SPITransfer'
v suboroch SpiTransfer.h a SpiTransfer.cpp som skusal odkomentovat tento riadok hned na zaciatku: /* UNCOMMENT FOR USAGE
ale stale mi vyhadzje chybove hlasky. v starom PC o ktory som prisiel sa mi to podarilo nejako rozbehat ale teraz sa nad tym trapim uz par hodin a nic.neviem ci bola medzi tym nejako upravovana kniznica.

AstroMiK
Příspěvky: 592
Registrován: 08 pro 2017, 19:05
Reputation: 0

Re: SPI transfer

Příspěvek od AstroMiK » 11 bře 2023, 08:28

Hned ta první chyba je jasná.
Odkomentoval jsi skutečný komentář a překladač potom narazil na slovo 'UNCOMENT', kterému nerozumí.

Problém je, že nestačí jen nahradit víceřádkový komentář (/* */) za jednořádkový (//), ale asi se musí projít celý zdroják té knihovny a odkomentovat použité funkce.
Tu knihovnu neznám a fakt se mi to nechce zkoumat moc do hloubky, takže víc asi neporadím.
komentar.gif

Uživatelský avatar
kiRRow
Příspěvky: 1151
Registrován: 07 kvě 2019, 07:03
Reputation: 0
Bydliště: Opava

Re: SPI transfer

Příspěvek od kiRRow » 11 bře 2023, 10:17

Např z tohohle :

Kód: Vybrat vše

/*
 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;
}
*/
musí zůstat jen tohle

Kód: Vybrat vše

void SPITransfer::begin(SPIClass& _port, const configST configs, const uint8_t& _SS)
{
	port = &_port;
	packet.begin(configs);
	ssPin = _SS;
}
max takhle, když si chci ponechat ten popis funkce :

Kód: Vybrat vše

/*
 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;
}

Uživatelský avatar
kiRRow
Příspěvky: 1151
Registrován: 07 kvě 2019, 07:03
Reputation: 0
Bydliště: Opava

Re: SPI transfer

Příspěvek od kiRRow » 11 bře 2023, 10:23

akorát ten začátek je tak divně ... z

Kód: Vybrat vše

/* UNCOMMENT FOR USAGE
#if not(defined(MBED_H) || defined(__SAM3X8E__) || defined(DISABLE_SPI_SERIALTRANSFER)) // These boards are/will not be supported by SPITransfer.h
#include "SPITransfer.h"
*/
zůstane tohle

Kód: Vybrat vše

#if not(defined(MBED_H) || defined(__SAM3X8E__) || defined(DISABLE_SPI_SERIALTRANSFER)) // These boards are/will not be supported by SPITransfer.h
#include "SPITransfer.h"

minicico1
Příspěvky: 29
Registrován: 30 kvě 2019, 01:13
Reputation: 0

Re: SPI transfer

Příspěvek od minicico1 » 11 bře 2023, 21:04

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.

minicico1
Příspěvky: 29
Registrován: 30 kvě 2019, 01:13
Reputation: 0

Re: SPI transfer

Příspěvek od minicico1 » 13 bře 2023, 20:28

ahojte,
takze pomohlo ked som nainstaloval staru verziu kniznice.konkretne 3.0.5
tam je naozaj riadok v SerialTransfer.h ktory je popisany v komente #define DISABLE_SPI_SERIALTRANSFER 1
sketch mi konecne skompilovalo.

Odpovědět

Kdo je online

Uživatelé prohlížející si toto fórum: Žádní registrovaní uživatelé a 3 hosti