2014-05-19 47 views
-6

我在这里是新的,发布,因为我已经阅读了几篇文章,有帮助我。我知道你可以把这篇文章看作是另一个重复,不。这不是重复的,因为我的代码与其他代码不同。这里是我的代码:编译错误:期望的构造函数,析构函数或类型转换之前';'token

#include "bcm2835.h" 
#include <cmath> 
#include <iostream> 
using namespace std; 


// COMMANDS 
#define WAKEUP 0x02 
#define SLEEP 0x04 
#define RESET 0x06 
#define START 0x09 
#define STOP 0x0a 
#define RDATAC 0x10 
#define SDATAC 0x11 
#define RDATA 0x12 
#define OFSCAL 0x18 
#define GANCAL 0x19 
#define RREG1 0x20 
#define WREG1 0x40 
#define RREG2 0x08 
#define WREG2 0x08 

// REGISTERS 
#define CONFIG0 0x85 
#define CONFIG1 0x10  // checksum is kept off 
#define CONFIG2 0x15  //10SPS data rate and Gate control mode 
#define OFC0 0x00 
#define OFC1 0x00 
#define OFC2 0x00 
#define FSC0 0x00 
#define FSC1 0x00 
#define FSC2 0x40 
#define NUM  1024 

int nobytes; 
int S = 50; 
int i,flag = 1; 
int j, k, factor, converged, count = 0; 
char status = LOW; 
char txbuffer[11], rxbuffer[4], dummy; 
float xhat, xhat_m, P_m, L , K, last_xhat_converged, xhat_converged = 0.0; 
float P = 1.0; 
float R = 0.01; 
float Q, mean, variance = 0; 
float current, lastreading, current_test[50]; 
double key, startkey; 
float X1[4096]; 
float X2[4096]; 
float Xf1[4096]; 
float Xf2[4096]; 
float v[4096]; 
float xf[4096]; 
float c[65536]; 
float ys[65536]; 

spi_start(); 
initialise(); 


void spi_start() 
{ 
bcm2835_init(); 
//cout << "The SPI mode is starting"; 
// INITIAL SETUP OF THE SPI DEVICE 
bcm2835_spi_begin();           // Setup the SPI0 port on the RaspberryPi 
bcm2835_spi_chipSelect(BCM2835_SPI_CS0);      // Assert the chip select 
bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);  // Set the Bit order 
bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);  // Set the the chip select to be active low 
bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_64); // Set the clock divider, SPI speed is 3.90625MHz 
bcm2835_spi_setDataMode(BCM2835_SPI_MODE1);     // Set the Data mode 
//cout << "The SPI mode has been started"; 
} 

void initialise() 
{ 
// INITIAL RESET OF THE CHIP 
nobytes = 1; 
txbuffer[0] = RESET; 
bcm2835_spi_writenb(txbuffer, nobytes); 
bcm2835_delay(100); //no accurate timing required 

// WRITING OF THE CONTROL AND THE CALIBRATION REGISTERS 
nobytes = 11; 
txbuffer[0] = WREG1; 
txbuffer[1] = WREG2; 
txbuffer[2] = CONFIG0; 
txbuffer[3] = CONFIG1; 
txbuffer[4] = CONFIG2; 
txbuffer[5] = OFC0; 
txbuffer[6] = OFC1; 
txbuffer[7] = OFC2; 
txbuffer[8] = FSC0; 
txbuffer[9] = FSC1; 
txbuffer[10]= FSC2; 
bcm2835_spi_writenb(txbuffer, nobytes); 
bcm2835_delay(100); //no accurate timing required 

} 

建议将不胜感激。

+1

很难知道去哪里找,没有看到错误消息 –

+1

不要把意见上定义了行号 – Leeor

+0

不要什么时候应该使用'#define'使用'const' – Mgetz

回答

0

你的问题是,你是在混淆编译:

spi_start(); 
initialize(); 

是函数调用,而不是函数声明。
请包括返回类型:

void spi_start(); 
void initialise(); 
+0

多么愚蠢的错误....非常感谢.. – lkkkk

+0

是从C移植的代码? K&R c允许您省略返回类型,默认为int。 –

相关问题