Chyba: expected ')' before '*' token u DS2450

C,C++,C#

Moderátori: psichac, Moderátori

blazenabc
Stály člen
Stály člen
Príspevky: 102
Dátum registrácie: 16 Nov 2014, 10:41

Chyba: expected ')' before '*' token u DS2450

Príspevok od používateľa blazenabc » 22 Nov 2014, 22:03

Ahoj.
Dneska si hraju s procesorem ATmega8. Rozblikal jsem LED a abych se nenudil, tak jsem si řekl, že zkusím implementovat nějakou knihovnu z internetu.

Našel jsem doma DS2450 a stáhl požadovanou knihovnu, ale v programu mám pár chyb. A jelikož jsem nedávno teprve začal, tak se chci zeptat, co je to za chyby, a jak je eliminovat. Určitě totiž na ně ještě narazím, tak se ptám radši hned teď, ať jsem o něco moudřejší.

Chyba:

Kód: Vybrať všetko

../ds2450.h:79: error: expected ')' before '*' token
Chápu to tak, že na řádku 79 očekává závorku před pointrem. Ale jak ji aplikovat, aby to přeložil správně??

Kód: Vybrať všetko

uint8_t  ds2450Setup(dallas_rom_id_T *rom_id, uint8_t channel, uint8_t resolution, uint8_t range);
Děkuji
0

anonymousCoward
Stály člen
Stály člen
Príspevky: 150
Dátum registrácie: 12 Máj 2013, 11:09
Bydlisko: KE

Re: Chyba: expected ')' before '*' token u DS2450

Príspevok od používateľa anonymousCoward » 22 Nov 2014, 22:13

Hlasky kompilatora C netreba brat doslovne :)
V tomto pripade asi nie je znamy typ dallas_rom_id_T ... pravdepodobne, bez kompletnejsich zdrojakov mozeme len hadat.
0
War is peace. Freedom is slavery. Ignorance is strength.
There is no such thing as a well-adjusted slave.

blazenabc
Stály člen
Stály člen
Príspevky: 102
Dátum registrácie: 16 Nov 2014, 10:41

Re: Chyba: expected ')' before '*' token u DS2450

Príspevok od používateľa blazenabc » 22 Nov 2014, 22:26

jjasné.
DS2450.h

Kód: Vybrať všetko

//*****************************************************************************
// File Name	: ds2450.c
// Title		: Dallas 1-Wire DS2450 A2D Sensor Library
// Revision		: 5
// Notes		: 
// Target MCU	: Atmel AVR series
// Editor Tabs	: 4
// 
// Revision History:
// When			Who			Rev		Description of change
// -----------	-----------	-------	-----------------------
// 07-Aug-2006	pwilliams	6		Fixed Error in strupr usage causing stack corruption
// 01-Oct-2003	rwatson		5		Fixed result error with MSB
// 30-Sep-2003	rwatson		4		CreatedDigitalOut
// 30-Sep-2003	rwatson		3		Created SetupAlll, StartAll, ResultAll, StartAndResultAll
// 29-Sep-2003	rwatson		2		Created Setup, Start, Result, StartAndResult
// 29-Sep-2003	rwatson		1		Created the program structure
//*****************************************************************************

#ifndef ds2450_h
#define ds2450_h


//----- Defines ---------------------------------------------------------------
#define ds2450_rev					6

// the two voltage ranges
#define DS2450_RANGE_2V				0x00    // 0-2.55V
#define DS2450_RANGE_5V				0x01    // 0-5.10V

// the family code
#define DS2450_FAMILY				0x20

// the starting addresses
// of the pages in RAM
#define DS2450_DATA_PAGE			0x00
#define DS2450_SETUP_PAGE			0x08
#define DS2450_ALARM_PAGE			0x10

#define DS2450_VCC_FLAG				0x40
#define DS2450_VCC_ADDR				0x1C

// maximum allowable resolution
#define DS2450_RES_MAX				16

// function commands
#define DS2450_READ_MEMORY			0xAA
#define DS2450_WRITE_MEMORY			0x55
#define DS2450_CONVERT				0x3C
#define DS2450_CONVERT_ALL4_MASK	0x0F
#define DS2450_CLEAR_ALL4_MASK		0x55

//----- Typedefs --------------------------------------------------------------

// enumerated constant for configuring
// and controlling an A2D channel as a digital output
typedef enum {DIGOUT_LOW=0x80, DIGOUT_OC=0xC0, DIGOUT_DISABLE=0x00} dallas_a2d_out_T;

//----- Functions ---------------------------------------------------------------

// ds2450Init()
//     initializes the dallas 1-wire bus
void ds2450Init(void);

//----- Single Channel Functions ----------------------------------------------
// The following 4 functions are used for controlling a single channel on the
// a2d converter.  If you are only using 1 channel, then these functions are
// faster.  If you are using 2 or more channel, it is faster to use the All
// Channel Functions.  This is because to convert all the channel only requires
// one command to the device, and then a read of the all the channel.  To read
// two channel individually requires two commands to the device, and two reads.
// Therefore using the All Channel Functions for even just 2 channels is faster
// and more effificient.

// ds2450Setup()
//     Sets up the given device, for the given channel [A-D],
//     the given resolution [1-16] and the given range 0-2.55 or 0-5.10
//     Returns either the corresponding error or DALLAS_NO_ERROR
uint8_t  ds2450Setup(dallas_rom_id_T *rom_id, uint8_t channel, uint8_t resolution, uint8_t range);

// ds2450Start()
//     Starts the a2d conversion for the given device and the given channel [A-D]
//     Returns either the corresponding error or DALLAS_NO_ERROR
uint8_t  ds2450Start(dallas_rom_id_T *rom_id, uint8_t channel);

// ds2450Result()
//     Gets the result from the a2d conversion
//     for the given device and the given channel [A-D]
//     Returns either the corresponding error or DALLAS_NO_ERROR
uint8_t  ds2450Result(dallas_rom_id_T *rom_id, uint8_t channel, uint16_t *result);

// ds2450StartAndResult()
//     Starts the conversion of the given device and the given channel [A-D]
//     Stores the result in the variable result
//     Returns either the corresponding error or DALLAS_NO_ERROR
uint8_t  ds2450StartAndResult(dallas_rom_id_T* rom_id, uint8_t channel, uint16_t *result);

//----- All Channel Functions -------------------------------------------------
// The following 4 commands are used to access data from all 4 channels on the
// a2d converter.  These commands should be used if you are using more than one
// channel on the device.  See the Single Channel Functions description for
// more information

// ds2450SetupAll()
//     Sets up the given device for all channels for the given resultion
//     and the given range [0-2.55 or 0-5.10]
//     Returns either the corresponding error or DALLAS_NO_ERROR
uint8_t  ds2450SetupAll(dallas_rom_id_T* rom_id, uint8_t resolution, uint8_t range);

// ds2450StartAll()
//     Starts the conversion for all 4 channels on the given a2d converter
//     Returns either the corresponding error or DALLAS_NO_ERROR
uint8_t  ds2450StartAll(dallas_rom_id_T* rom_id);

// ds2450ResultAll
//     Gets the results from the given device
//     and stores the result in the given array
//     Returns either the corresponding error or DALLAS_NO_ERROR
uint8_t  ds2450ResultAll(dallas_rom_id_T* rom_id, uint16_t result[4]);

// ds2450StartAndResultAll()
//     1-Step command to start the conversion for the given device,
//     and store the results in the given array
//     Returns either the corresponding error or DALLAS_NO_ERROR
uint8_t  ds2450StartAndResultAll(dallas_rom_id_T* rom_id, uint16_t result[4]);

// ds2450Print()
//     Does a formatted print on the given result for the given range
//void ds2450Print(uint16_t result, uint8_t range);

//----- Digital Out Functions -------------------------------------------------
// ds2450DigitalOut
//     Use the given channel of the given device as a digital out
//     Returns either the corresponding error or DALLAS_NO_ERROR
uint8_t  ds2450DigitalOut(dallas_rom_id_T* rom_id, uint8_t channel, dallas_a2d_out_T state);

#endif
DS2450.c

Kód: Vybrať všetko

//*****************************************************************************
// File Name	: ds2450.c
// Title		: Dallas 1-Wire DS2450 A2D Sensor Library
// Revision		: 5
// Notes		: 
// Target MCU	: Atmel AVR series
// Editor Tabs	: 4
// 
//*****************************************************************************

//----- Include Files ---------------------------------------------------------
#include <string.h>			// include string support
#include <ctype.h>
#include "timer128.h"
#include "dallas.h"			// include dallas support
#include "ds2450.h"			// include ds2450 support
/*#include "rprintf.h"*/

//----- Functions ---------------------------------------------------------------

/*--------------------------------------------------------------------------
 * ds2450Chan2Addr: converts the channel to the address in RAM
 * input........... channel - the channel to get the address for [A-D]
 *                  page - the page in RAM that we are dealing with
 *                  address - where the address is stored
 * returns......... the corresponding error or DALLAS_NO_ERROR
 *-------------------------------------------------------------------------*/
static uint8_t ds2450Chan2Addr(uint8_t channel, uint8_t page, uint16_t *address);

void ds2450Init(void)
{
	// initialize the dallas 1-wire
	dallasInit();
}

uint8_t *capitalize (uint8_t *input)
{
	if(islower(*input))
		*input = toupper(*input);
	return input;
}

uint8_t ds2450Setup(dallas_rom_id_T* rom_id, uint8_t channel, uint8_t resolution, uint8_t range)
{
	uint8_t error;
	uint8_t data[2];
	uint16_t address;

	// check resolution
	if (resolution > DS2450_RES_MAX)
		return DALLAS_RESOLUTION_ERROR;

	// check address
	error = dallasAddressCheck(rom_id, DS2450_FAMILY);
	if (error != DALLAS_NO_ERROR)
		return error;

	// get address
	capitalize(&channel);
	error = ds2450Chan2Addr(channel, DS2450_SETUP_PAGE, &address); 	//find starting address
	if (error != DALLAS_NO_ERROR)
		return error;

	// convert to valid resolution - 16 bits = 0x00
	if (resolution == 16)
		resolution = 0x00;

	// read in current digital output settings
	error = dallasReadRAM(rom_id, address, 1, data);
	if (error != DALLAS_NO_ERROR)
		return error;

	// maintain digital output portion and add new resolution
	data[0] = (data[0] & 0xF0) | resolution;
	
	// maintain alarm states and add new range
	data[1] = (data[1] & 0xFE) | range;

	// actually write config, handles CRC too
	error = dallasWriteRAM(rom_id, address, 2, data);
	if (error != DALLAS_NO_ERROR)
		return error;

	// Normally, the DS2450 is designed to run off of parasite power from the data line
	// Typically the master (us) strongly pulls high long enough to power the conversion, so
	// there is inherintly a long () delay introduced. Since the A2D code is designed to
	// work for devices that use external power, we can elliminate this delay by writting
	// the following byte per the DS2450 datasheet.
	data[0] = DS2450_VCC_FLAG;
	error = dallasWriteRAM(rom_id, DS2450_VCC_ADDR, 1, &data[0]);
	if (error != DALLAS_NO_ERROR)
		return error;

	// verify the data
	error = dallasReadRAM(rom_id, address, 2, data);
	if (error != DALLAS_NO_ERROR)
		return error;

	if ((data[0] & 0x0F) != resolution)
		return DALLAS_VERIFY_ERROR;
	if ((data[1] & 0x01) != range)
		return DALLAS_VERIFY_ERROR;

	return DALLAS_NO_ERROR;
}

uint8_t ds2450Start(dallas_rom_id_T* rom_id, uint8_t channel)
{
	uint8_t mask;
	uint8_t error;
	uint8_t crc[2];

	// check address
	error = dallasAddressCheck(rom_id, DS2450_FAMILY);
	if (error != DALLAS_NO_ERROR)
		return error;

	// make sure the channel is a capital letter
	capitalize(&channel);
	// convert to integer 0 to 3
	channel -= 'A';

	// make sure channel is a valid value
	if (channel > 3)
		return DALLAS_INVALID_CHANNEL;

	// shift over to construct input select mask
	mask = 0x01 << channel;

	// reset and select node
	error = dallasMatchROM(rom_id);
	if (error != DALLAS_NO_ERROR)
		return error;

	// send convert command
	dallasWriteByte(DS2450_CONVERT);
	// input select mask
	dallasWriteByte(mask);
	// shift over some more for "read-out" control
	mask = mask << channel;
	
	// set coresponding output buffer to zero	
	dallasWriteByte(mask);

	// we must read 2byte CRC16 to start the conversion:
	crc[0] = dallasReadByte();
	crc[1] = dallasReadByte();

	//replace with explicit CRC posibilities lookup table
//	if (crc[0] == 0xFF && crc[1] == 0xFF)
//		return DALLAS_DEVICE_ERROR;        //if CRC = all one's, no one is paying attention

	return DALLAS_NO_ERROR;
}

uint8_t ds2450Result(dallas_rom_id_T* rom_id, uint8_t channel, uint16_t* result)
{
	uint8_t data[2];
	uint8_t error;
	uint16_t address;
	//u08 resolution;

	// check address
	error = dallasAddressCheck(rom_id, DS2450_FAMILY);
	if( error != DALLAS_NO_ERROR)
		return error;

	// get the RAM address for the data for the channel
	capitalize(&channel);
	error = ds2450Chan2Addr(channel, DS2450_DATA_PAGE, &address);
	if (error != DALLAS_NO_ERROR)
		return error;

	// read the RAM from the device to get the data
	error = dallasReadRAM(rom_id, address, 2, data);
	/*
	// get the address for the setup for the channel
	error = ds2450Chan2Addr(channel, DS2450_SETUP_PAGE, &address); 	//find starting address
	if (error != DALLAS_NO_ERROR)
		return error;
	
	// read the RAM from the device to get the resolution
	error = dallasReadRAM(rom_id, address, 1, &resolution);
	if (error != DALLAS_NO_ERROR)
		return error;

	// get the resultion part of the data
	resolution &=0x0F;
	*/
	// store the result by combining the 2 bytes
	// the result's MSB is always the same, so we may need to
	// shift the data over so that the LSB is at the first bit
	*result = 0;
	//*result = (((u16)data[1] << 8) | data[0]) >> (16 - resolution);
	*result = (((uint16_t)data[1] << 8) | data[0]);

	return DALLAS_NO_ERROR;
}

uint8_t ds2450StartAndResult(dallas_rom_id_T* rom_id, uint8_t channel, uint16_t *result)
{
	uint8_t error;

	// start conversion
	error = ds2450Start(rom_id, channel);
	if (error != DALLAS_NO_ERROR)
		return error;
	
	// wait till conversion done
	dallasWaitUntilDone();
	
	// return results
	return ds2450Result(rom_id, channel, result);
}

uint8_t ds2450SetupAll(dallas_rom_id_T* rom_id, uint8_t resolution, uint8_t range)
{
	uint8_t i;
	uint8_t error;
	uint8_t data[8];
	uint16_t address;

	// check address
	error = dallasAddressCheck(rom_id, DS2450_FAMILY);
	if (error != DALLAS_NO_ERROR)
		return error;

	// check resolution
	if (resolution > DS2450_RES_MAX)
		return DALLAS_RESOLUTION_ERROR;

	// convert to valid resolution - 16 bits = 0x00
	if (resolution == 16)
		resolution = 0;

	// get address - start with channel A
	error = ds2450Chan2Addr('A', DS2450_SETUP_PAGE, &address);
	if (error != DALLAS_NO_ERROR)
		return error;

	// read in current settings so we can extract digital part
	error = dallasReadRAM(rom_id, address, 8, data);
	if (error != DALLAS_NO_ERROR)
		return error;

	// build up config data to write - increment by 2 b/c two bytes per channel
	for(i=0;i<8;i+= 2)
	{ 
		// maintain digital output settings
		data[i] &= 0xF0;	// extract digital output portion
		data[i+1] &= 0xFE;

		// write resolution byte and range
		data[i] |= resolution;
		data[i+1] |= range;
	}

	// actually write config - handles CRC too
	error = dallasWriteRAM(rom_id, address, 8, data);
	if (error != DALLAS_NO_ERROR)
		return error;

	// Normally, the DS2450 is designed to run off of parasite power from the data line
	// Typically the master (us) strongly pulls high long enough to power the conversion, so
	// there is inherintly a long () delay introduced. Since the A2D code is designed to
	// work for devices that use external power, we can elliminate this delay by writting
	// the following byte per the DS2450 datasheet.
	data[0] = DS2450_VCC_FLAG;
	error = dallasWriteRAM(rom_id, DS2450_VCC_ADDR, 1, &data[0]);
	if (error != DALLAS_NO_ERROR)
		return error;

	error = dallasReadRAM(rom_id,address,8,data);
	if (error != DALLAS_NO_ERROR)
		return error;

	for(i=0;i<8;i+=2)
	{
		if ((data[i] & 0x0F) != resolution)
			return DALLAS_VERIFY_ERROR;
		if ((data[i+1] & 0x01) != range)
			return DALLAS_VERIFY_ERROR;
	}

	return DALLAS_NO_ERROR;
}

uint8_t ds2450StartAll(dallas_rom_id_T* rom_id)
{
	uint8_t error;
	uint16_t crc;

	// check address
	error = dallasAddressCheck(rom_id, DS2450_FAMILY);
	if (error != DALLAS_NO_ERROR)
		return error;

	// reset and select node
	error = dallasMatchROM(rom_id);
	if (error != DALLAS_NO_ERROR)
		return error;

	dallasWriteByte(DS2450_CONVERT);			// send convert command
	dallasWriteByte(DS2450_CONVERT_ALL4_MASK);  	// select all 4 inputs
	dallasWriteByte(DS2450_CLEAR_ALL4_MASK);		// set all output buffers to zero

	// we must read 2byte CRC16 to start the conversion:
	crc = dallasReadByte() | ((uint16_t)dallasReadByte() << 8);

	// replace with explicit CRC posibilities lookup table
//	if (crc == 0xFFFF)
//		return DALLAS_DEVICE_ERROR;        // if CRC = all one's, no one is paying attention
	
	return DALLAS_NO_ERROR;
}

uint8_t ds2450ResultAll(dallas_rom_id_T* rom_id, uint16_t result[4])
{
	//const u08 bytes_to_read = 10;		// read 10bytes = 2/ch*4ch + CRC
	uint8_t bytes_to_read = 10;
	uint8_t i;
	uint8_t error;
	uint8_t data[10];
	uint8_t resolution[10];
	uint16_t address;

	// check address
	
	error = dallasAddressCheck(rom_id, DS2450_FAMILY);
	if (error != DALLAS_NO_ERROR)
		return error;

	// start address with channel A
	error = ds2450Chan2Addr('A', DS2450_DATA_PAGE, &address);
	if (error != DALLAS_NO_ERROR)
		return error;

	// read the conversion data
	error = dallasReadRAM(rom_id, address, bytes_to_read, data);
	if (error != DALLAS_NO_ERROR)
		return error;

	//FUTURE: do a real CRC16 check

	// start address with channel A
	error = ds2450Chan2Addr('A', DS2450_SETUP_PAGE, &address);
	if (error != DALLAS_NO_ERROR)
		return error;

	// read the resolution data
	error = dallasReadRAM(rom_id, address, bytes_to_read, resolution);
	if (error != DALLAS_NO_ERROR)
		return error;

	// check crc?

	// store the result by combining the 2 bytes
	// the result's MSB is always the same, so we may need to
	// shift the data over so that the LSB is at the first bit
	error=0;
	for(i=0;i<8;i+=2)
	{
		resolution[i] &= 0x0F;
		if (!resolution[i])
			resolution[i] = 16;

		result[error] = 0;
		//result[error] = (((u16)data[i+1] << 8) | data[i]) >> (16 - resolution[i]);
		result[error] = (((uint16_t)data[i+1] << 8) | data[i]);
		error++;
	}

	return DALLAS_NO_ERROR;
}

uint8_t ds2450StartAndResultAll(dallas_rom_id_T* rom_id, uint16_t result[4])
{
	uint8_t error;

	// start Conversion
	error = ds2450StartAll(rom_id);
	if (error != DALLAS_NO_ERROR)
		return error;
	
	// wait until conversion done
	dallasWaitUntilDone();
	
	// return any error - results passed by reference
	return ds2450ResultAll(rom_id, result);
}

/*void ds2450Print(uint16_t result, uint8_t range)
{
	uint16_t vscale;

	rprintfProgStrM(" 0x");
	rprintfu16(result);
	rprintf("  ");
	if(range)
		vscale = 12800;
	else
		vscale = 25600;

	rprintfNum(10, 4, TRUE , ' ', result/vscale);
	rprintf(".");
	rprintfNum(10, 4, FALSE, '0', (((u32)(result%vscale))*10000)/vscale );
	rprintfProgStrM(" Volts");
}
*/
uint8_t ds2450DigitalOut(dallas_rom_id_T* rom_id, uint8_t channel, dallas_a2d_out_T state)
{
	uint8_t error;
	uint8_t old_resolution;
	uint16_t address;

	// check address
	error = dallasAddressCheck(rom_id, DS2450_FAMILY);
	if (error != DALLAS_NO_ERROR)
		return error;

	// get the address for the channel in the setup page
	error = ds2450Chan2Addr(channel, DS2450_SETUP_PAGE, &address);
	if (error != DALLAS_NO_ERROR)
		return error;

	// read in current resolution
	error = dallasReadRAM(rom_id, address, 1, &old_resolution);
	if (error != DALLAS_NO_ERROR)
		return error;
	
	// extract resolution portion
	old_resolution &= 0x0F;

	// write new setup byte
	state |= old_resolution;
	error = dallasWriteRAM(rom_id, address, 1, ((uint8_t*)&state));
	if (error != DALLAS_NO_ERROR)
		return error;

	return DALLAS_NO_ERROR;
}

static uint8_t ds2450Chan2Addr(uint8_t channel, uint8_t page, uint16_t *address)
{
	// make sure the channel is a capital letter
	capitalize(&channel);

	//convert to integer 0 to 3 and check to see if it is valid
	channel -= 'A';
	if (channel > 3)
		return DALLAS_INVALID_CHANNEL;

	// use corresponding memory address
	*address = (channel<<1) + page;			// channel<<1 == channel*2, but faster

	return DALLAS_NO_ERROR;
}
A tady je ten dallas_rom_id_T

Kód: Vybrať všetko

typedef union dallas_rom_id_U
{
	long long id;
	uint8_t byte[8];
} dallas_rom_id_T;
0

anonymousCoward
Stály člen
Stály člen
Príspevky: 150
Dátum registrácie: 12 Máj 2013, 11:09
Bydlisko: KE

Re: Chyba: expected ')' before '*' token u DS2450

Príspevok od používateľa anonymousCoward » 22 Nov 2014, 23:02

Predpokladam, ze ten dallas_rom_id_T je definovany v dallas.h (zeby https://avr-liberty.googlecode.com/svn/ ... l/dallas.h ?).
#include "dallas.h" je v DS2450.c, ale zrejme sa DS2450.h #includuje aj niekde inde - v tom mieste sa uz ale samotny dallas.h neincluduje (v main.c ?), co sposobi chybovu hlasku, lebo dallas_rom_id_T v tom momente prekladac nepozna.

Fix je bud pred #include "DS2450.h" dat prislusny #include "dallas.h" (v spominanom main.c, ci inde), alebo tento #include "dallas.h" dat na zaciatok DS2450.h, idealne za riadky #ifdnef .. #define . V druhom pripade mozes z DS2450.c vyhodit #include "dallas.h".
Ten druhy sposob je asi cistejsi, ale to je na diskusiu ..
0
War is peace. Freedom is slavery. Ignorance is strength.
There is no such thing as a well-adjusted slave.

blazenabc
Stály člen
Stály člen
Príspevky: 102
Dátum registrácie: 16 Nov 2014, 10:41

Re: Chyba: expected ')' before '*' token u DS2450

Príspevok od používateľa blazenabc » 23 Nov 2014, 00:09

Ano měl jsi pravdu. Toto otevřelo 55 Chyb. :D Takže na implementaci knihovny jsem krátký. :D
0

anonymousCoward
Stály člen
Stály člen
Príspevky: 150
Dátum registrácie: 12 Máj 2013, 11:09
Bydlisko: KE

Re: Chyba: expected ')' before '*' token u DS2450

Príspevok od používateľa anonymousCoward » 23 Nov 2014, 08:00

Knihovnu pre DS2450 staci stiahnut, takze asi skor myslis pouzitie, nie implementaciu - to je o cosi jednoduchsie nez naopak.
Tych 55 chyb moze byt zapricinenych jednym/dvoma preklepmi - to je dalsia 'vyhoda' C :)
Postni sem cely vypis z kompilatora + zvysok kodu, idealne ako prilohu, spolu s Makefile resp. s nastaveniami projektu, a niekto Ti urcite pomoze.
0
War is peace. Freedom is slavery. Ignorance is strength.
There is no such thing as a well-adjusted slave.

blazenabc
Stály člen
Stály člen
Príspevky: 102
Dátum registrácie: 16 Nov 2014, 10:41

Re: Chyba: expected ')' before '*' token u DS2450

Príspevok od používateľa blazenabc » 23 Nov 2014, 12:50

Tak jsem sw rozhodl, že si zkusím napsat vlastní knihovnu pro DS2450 s ověřenou knihovnou pro 1-Wire.

Otevřel jsem datasheet, knihovnu pro DS18B20, která je OK a začal jsem upravovat. Jenže nyní jsem zamrzl. Nedaří se mi vyčíst hodnota ADC. CRC zatím neřeším a více čidel také ne.

Všechny knihovny jsou na konci vlákna. Pokud se snažím zkompilovat funkci:

Kód: Vybrať všetko

void read_memory(char* buff1, char* buff2)
{
		uint16_t data[5];

        ow_command( DS2450_MEM, id );
        
        data[0] = ow_byte_rd();
		_delay_us(5);
		data[1] = ow_byte_rd();
		_delay_us(5);

		sprintf(buff1,"%04u",data[0]);
		sprintf(buff2,"%04u",data[1]);
}
Nyní už to přeloží, ale nevím co dosadit za id -> ow_command( DS2450_MEM, id );
Prílohy
onewire.c
(8.44 KiB) 27 stiahnutí
onewire.h
(2.7 KiB) 28 stiahnutí
ds2450.c
(2.32 KiB) 31 stiahnutí
ds2450.h
(700 Bajtov) 26 stiahnutí
0

anonymousCoward
Stály člen
Stály člen
Príspevky: 150
Dátum registrácie: 12 Máj 2013, 11:09
Bydlisko: KE

Re: Chyba: expected ')' before '*' token u DS2450

Príspevok od používateľa anonymousCoward » 23 Nov 2014, 13:44

Zmenil si mi to pod rukami, takze Ti postnem co k tomu mam, a k zvysku sa vyjadrim po obede:
conflicting types for 'read_memory'
../ds2450.h:28: error: previous declaration of 'read_memory' was here
To znamena, ze deklaracia fcie read_memory (v ds2450.h) sa lisi od definicie v ds2450.c - podla signatury v headeri ocakava jeden parameter (char* buff), ale neskor ju uz definujes s dvoma: char* buff1, char* buff2
Ak tam ma byt jeden, oprav to v ds2450.c; ak maju byt predsa len dva, zmen header.
./ds2450.c: In function 'read_memory':
../ds2450.c:76: error: expected identifier or '(' before 'volatile'
../ds2450.c:76: error: expected ')' before '(' token
Toto je pomerne matuca chyba - problem je v premennej ADC, a to v tom, ze sa niekde v kniznicnych headeroch #definuje ako makro, ktore obsahuje volatile. Premennuj ju na nieco ine. Tu tazko radit do buducnosti, snad len to, ze je dobre pouzivat viacpismenkove nazvy pre premenne, makra a funkcie - okrem toho, ze sa vyhnes podobnym prekvapeniam, urobis sluzbu sebe aj inym, ked nebudu musiet hadat co znamena napr. rvfa2 - namiesto toho radsej pouzi cosi ako rawValueFromAdc atd.
./ds2450.c: In function 'read_memory':
...
../ds2450.c:78: error: 'id' undeclared (first use in this function)
../ds2450.c:78: error: (Each undeclared identifier is reported only on
Tieto riadky znamenaju ze premenna id nie je deklarovana - kedze neviem, co si vlastne chcel, tak Ti s tymto konkretnejsie neporadim :)

Okrem toho Ti dorazne odporucam zapnut si warningy (-Wall ? zavisi od kompilatora ktory pouzivas). Tak by si sa este dozvedel (okrem ineho) ze:
ds2450.c:72:24: warning: unused parameter ‘buff1’ [-Wunused-parameter]
Je totiz o dost lahsie nechat na seba nakricat kompilatorom, nez sa nahanat za chybami pri ladeni.


Dalsia chyba je pouzitie nedeklarovanej premennej buff v tej istej fcii - asi si ju zabudol premenovat na buff1.
0
War is peace. Freedom is slavery. Ignorance is strength.
There is no such thing as a well-adjusted slave.

blazenabc
Stály člen
Stály člen
Príspevky: 102
Dátum registrácie: 16 Nov 2014, 10:41

Re: Chyba: expected ')' before '*' token u DS2450

Príspevok od používateľa blazenabc » 23 Nov 2014, 13:55

Ty warningy mám zapnuté.

Používám AVR STUDIO 4 s WinAVR.
0

anonymousCoward
Stály člen
Stály člen
Príspevky: 150
Dátum registrácie: 12 Máj 2013, 11:09
Bydlisko: KE

Re: Chyba: expected ')' before '*' token u DS2450

Príspevok od používateľa anonymousCoward » 23 Nov 2014, 15:16

Ad warningy: super :)

Parameter id zjavne urcuje ID one wire zariadenia s ktorym chces komunikovat. Ak tam zadas 0, komunikujes so vsetkymi - pozri kod v ow_command_intern().
Fix zavisi prave od toho - ak chces komunikovat s konkretnym zariadenim, musis jeho ID mat vo svojej funkcii read_memory() - ak ho nevies urcit tam, bolo by vhodne predat ho tejto funkcii ako parameter: uint8_t *id a idealne ako posledny parameter fcie, nech vsetky fcie vyzeraju rovnako.
0
War is peace. Freedom is slavery. Ignorance is strength.
There is no such thing as a well-adjusted slave.

blazenabc
Stály člen
Stály člen
Príspevky: 102
Dátum registrácie: 16 Nov 2014, 10:41

Re: Chyba: expected ')' before '*' token u DS2450

Príspevok od používateľa blazenabc » 25 Nov 2014, 20:24

Tak už se mi zadařilo, ale pořád mám nějaké chyby. Data už vyčítám, ale něco dělám špatně. Zobrazená data mám chybné se znaménkem -.

Zatím se snažím jen zobrazit hodnotu ADC.

Kód: Vybrať všetko

DS2450_configure_channel_ADC(&gSensorIDs[num_sensor][0],DS2450_ADCA,DS2450_12_BIT ,DS2450_IR_5V1);
DS2450_configure_channel_ADC(&gSensorIDs[num_sensor][0],DS2450_ADCB,DS2450_12_BIT ,DS2450_IR_5V1);
DS2450_configure_channel_ADC(&gSensorIDs[num_sensor][0],DS2450_ADCC,DS2450_12_BIT ,DS2450_IR_5V1);
DS2450_configure_channel_ADC(&gSensorIDs[num_sensor][0],DS2450_ADCD,DS2450_12_BIT ,DS2450_IR_5V1);
				
		for(i=0; i<4; ){
			DS2450_start_and_read_ADC(&gSensorIDs[num_sensor][0], &adc[0]);    //precte a ulozi vsechny 4 ADC
			sprintf(buffer, "adc:%06d \r\n",adc[i]);  //vypis hodnot ADC
			uart_puts(buffer);
			i++;
		}
Knihovny DS2450 jsou níže.
Prílohy
ds2450.c
(8.25 KiB) 29 stiahnutí
ds2450.h
(1.75 KiB) 29 stiahnutí
0

anonymousCoward
Stály člen
Stály člen
Príspevky: 150
Dátum registrácie: 12 Máj 2013, 11:09
Bydlisko: KE

Re: Chyba: expected ')' before '*' token u DS2450

Príspevok od používateľa anonymousCoward » 25 Nov 2014, 21:18

Akeho typu su prvky pola adc ? Fcia ocakava uint16_t - ak je to naozaj toho typu tak %d urcite nie je dobre. Pozri inttypes.h a pouzi prislusny literal:

Kód: Vybrať všetko

sprintf(buffer, "adc:%06"  PRIu16 " \r\n",adc[i]);
Okrem toho, si si isty ze DS2450_start_and_read_ADC() vrati OW_OK ?

A zase, bez kompletneho kodu to je viac hadanie nez seriozna diagnostika.
0
War is peace. Freedom is slavery. Ignorance is strength.
There is no such thing as a well-adjusted slave.

blazenabc
Stály člen
Stály člen
Príspevky: 102
Dátum registrácie: 16 Nov 2014, 10:41

Re: Chyba: expected ')' before '*' token u DS2450

Príspevok od používateľa blazenabc » 25 Nov 2014, 22:26

Jelikož jsem zapomněl DS2450 doma, tak jsem přesedlal na simulátor.

A ano, stačilo změnit výpis místo %d jsem použil %u, takže opět díky anonymousCoward za radu. A vypisuje mi 16 bitové číslo. Toto mi odpovídá i po přepočtu.

Kód: Vybrať všetko

if ( (gSensorIDs[num_sensor][0])== DS2450_ID) {
				DS2450_configure_channel_ADC(&gSensorIDs[num_sensor][0],DS2450_ADCA,DS2450_12_BIT ,DS2450_IR_5V1);
				DS2450_configure_channel_ADC(&gSensorIDs[num_sensor][0],DS2450_ADCB,DS2450_12_BIT ,DS2450_IR_5V1);
				DS2450_configure_channel_ADC(&gSensorIDs[num_sensor][0],DS2450_ADCC,DS2450_12_BIT ,DS2450_IR_5V1);
				DS2450_configure_channel_ADC(&gSensorIDs[num_sensor][0],DS2450_ADCD,DS2450_12_BIT ,DS2450_IR_5V1);

				for(i=0; i<4; ){
					DS2450_start_and_read_ADC(&gSensorIDs[num_sensor][0], &adc[0]);
					sprintf(buffer, "adc:%06u \r\n",adc[i]);
					uart_puts(buffer);
					i++;
				}
			}
Program pro emulaci DS2450 je v bascomu. ----------ODKAZ ZDE----------- A bascom já už vůbec neumím.

Program je ale udělaný tak, že vždy dostanu 16-bit číslo. Ale ti mi zas tak nevadí. :)
Prílohy
Výstřižek.PNG
0

Napísať odpoveď
  • Podobné témy
    Odpovedí
    Zobrazení
    Posledný príspevok