I'm having some issues with some code than i can figure out, anyone have any ideas?
72 1506 Implicit conversion of pointer to int MyProject.c
73 307 Illegal typecast 'can not convert to pointer' '' MyProject.c
73 1508 Implicit conversion of int to ptr MyProject.c
74 1506 Implicit conversion of pointer to int MyProject.c
82 402 ; expected, but 'SPI2_read' found MyProject.c
82 393 'SPI2_read' Identifier redefined MyProject.c
Code: Select all
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
long SPDR, PINB, PB4, SPSR, SPIF;
unsigned long buffer1;
unsigned long buffer2;
unsigned long buffer3;
unsigned long buffer4;
sbit cs_adc_v2 at LATE4_bit;
void InitMain() {
CHECON = 0x32;
AD1PCFG = 0xFFFF;
SPI2_Init_Advanced(_SPI_MASTER, _SPI_32_BIT, 64, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_IDLE_2_ACTIVE);
TRISE4_bit = 0;
cs_adc_v2 = 1;
UART1_Init(57600);
// init SPI Hardware
UART1_Write_Text("LTC2400 ADC Test");
}
float volt;
float v_ref=3.0; // Reference Voltage, 5.0 Volt for LT1021 or 3.0 for LP2950-3
long int ltw = 0; // ADC Data ling int
int cnt; // counter
char t0; //
char sig; // sign bit flag
char st1[20]; // float voltage text
/********************************************************************/
void Main() {
InitMain();
cs_adc_v2 = 0; // LTC2400 CS Low
Delay_ms(1);
if (!(PINB & (1 << PB4))) { // ADC Converter ready ?
// cli();
ltw=0;
sig=0;
t0 = SPI2_read(buffer1); // read 4 bytes adc raw data with SPI
if ((t0 & 0x20) ==0) sig=1; // is input negative ?
t0 &=0x1F; // discard bit 25..31
ltw |= t0;
ltw <<= 8;
t0 = SPI2_read(buffer2);
ltw |= t0;
ltw <<= 8;
t0 = SPI2_read(buffer3);
ltw |= t0;
ltw <<= 8;
t0 = SPI2_read(buffer4);
ltw |= t0;
Delay_us(1);
cs_adc_v2 = 0; // LTC2400 CS Low
Delay_ms(200);
if (sig) ltw |= 0xf0000000; // if input negative insert sign bit
ltw=ltw/16; // scale result down , last 4 bits have no information
volt = ltw * v_ref / 16777216; // max scale
UART1_Write(cnt++);
UART1_Write("; ");
sprintf(volt,6); // print voltage as floating number
UART1_Write(" ");
}
cs_adc_v2 =1; // LTC2400 CS hi
Delay_ms(20);
}
/********************************************************************/
byte SPI2_read()
{
SPDR = 0;
while (!(SPSR & (1 << SPIF))) ; /* Wait for SPI shift out done */
return SPDR;
}
/********************************************************************/
// printFloat from tim / Arduino: Playground
// printFloat prints out the float 'value' rounded to 'places' places
//after the decimal point
void printFloat(float value, int places) {
// this is used to cast digits
int digit;
float tens = 0.1;
int tenscount = 0;
int i;
float tempfloat = value;
// if value is negative, set tempfloat to the abs value
// make sure we round properly. this could use pow from
//<math.h>, but doesn't seem worth the import
// if this rounding step isn't here, the value 54.321 prints as
// calculate rounding term d: 0.5/pow(10,places)
float d = 0.5;
if (value < 0)
d *= -1.0;
// divide by ten for each decimal place
for (i = 0; i < places; i++)
d/= 10.0;
// this small addition, combined with truncation will round our
tempfloat += d;
if (value < 0)
tempfloat *= -1.0;
while ((tens * 10.0) <= tempfloat) {
tens *= 10.0;
tenscount += 1;
}
// write out the negative if needed
if (value < 0)
UART1_Write('-');
if (tenscount == 0)
UART1_Write(0);
for (i=0; i< tenscount; i++) {
digit = (int) (tempfloat/tens);
UART1_Write(digit);
tempfloat = tempfloat - ((float)digit * tens);
tens /= 10.0;
}
// if no places after decimal, stop now and return
if (places <= 0)
return;
// otherwise, write the point and continue on
UART1_Write(',');
for (i = 0; i < places; i++) {
tempfloat *= 10.0;
digit = (int) tempfloat;
UART1_Write(digit);
// once written, subtract off that digit
tempfloat = tempfloat - (float) digit;
}
}
72 1506 Implicit conversion of pointer to int MyProject.c
73 307 Illegal typecast 'can not convert to pointer' '' MyProject.c
73 1508 Implicit conversion of int to ptr MyProject.c
74 1506 Implicit conversion of pointer to int MyProject.c
82 402 ; expected, but 'SPI2_read' found MyProject.c
82 393 'SPI2_read' Identifier redefined MyProject.c
Code: Select all
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
long SPDR, PINB, PB4, SPSR, SPIF;
unsigned long buffer1;
unsigned long buffer2;
unsigned long buffer3;
unsigned long buffer4;
sbit cs_adc_v2 at LATE4_bit;
void InitMain() {
CHECON = 0x32;
AD1PCFG = 0xFFFF;
SPI2_Init_Advanced(_SPI_MASTER, _SPI_32_BIT, 64, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_IDLE_2_ACTIVE);
TRISE4_bit = 0;
cs_adc_v2 = 1;
UART1_Init(57600);
// init SPI Hardware
UART1_Write_Text("LTC2400 ADC Test");
}
float volt;
float v_ref=3.0; // Reference Voltage, 5.0 Volt for LT1021 or 3.0 for LP2950-3
long int ltw = 0; // ADC Data ling int
int cnt; // counter
char t0; //
char sig; // sign bit flag
char st1[20]; // float voltage text
/********************************************************************/
void Main() {
InitMain();
cs_adc_v2 = 0; // LTC2400 CS Low
Delay_ms(1);
if (!(PINB & (1 << PB4))) { // ADC Converter ready ?
// cli();
ltw=0;
sig=0;
t0 = SPI2_read(buffer1); // read 4 bytes adc raw data with SPI
if ((t0 & 0x20) ==0) sig=1; // is input negative ?
t0 &=0x1F; // discard bit 25..31
ltw |= t0;
ltw <<= 8;
t0 = SPI2_read(buffer2);
ltw |= t0;
ltw <<= 8;
t0 = SPI2_read(buffer3);
ltw |= t0;
ltw <<= 8;
t0 = SPI2_read(buffer4);
ltw |= t0;
Delay_us(1);
cs_adc_v2 = 0; // LTC2400 CS Low
Delay_ms(200);
if (sig) ltw |= 0xf0000000; // if input negative insert sign bit
ltw=ltw/16; // scale result down , last 4 bits have no information
volt = ltw * v_ref / 16777216; // max scale
UART1_Write(cnt++);
UART1_Write("; ");
sprintf(volt,6); // print voltage as floating number
UART1_Write(" ");
}
cs_adc_v2 =1; // LTC2400 CS hi
Delay_ms(20);
}
/********************************************************************/
byte SPI2_read()
{
SPDR = 0;
while (!(SPSR & (1 << SPIF))) ; /* Wait for SPI shift out done */
return SPDR;
}
/********************************************************************/
// printFloat from tim / Arduino: Playground
// printFloat prints out the float 'value' rounded to 'places' places
//after the decimal point
void printFloat(float value, int places) {
// this is used to cast digits
int digit;
float tens = 0.1;
int tenscount = 0;
int i;
float tempfloat = value;
// if value is negative, set tempfloat to the abs value
// make sure we round properly. this could use pow from
//<math.h>, but doesn't seem worth the import
// if this rounding step isn't here, the value 54.321 prints as
// calculate rounding term d: 0.5/pow(10,places)
float d = 0.5;
if (value < 0)
d *= -1.0;
// divide by ten for each decimal place
for (i = 0; i < places; i++)
d/= 10.0;
// this small addition, combined with truncation will round our
tempfloat += d;
if (value < 0)
tempfloat *= -1.0;
while ((tens * 10.0) <= tempfloat) {
tens *= 10.0;
tenscount += 1;
}
// write out the negative if needed
if (value < 0)
UART1_Write('-');
if (tenscount == 0)
UART1_Write(0);
for (i=0; i< tenscount; i++) {
digit = (int) (tempfloat/tens);
UART1_Write(digit);
tempfloat = tempfloat - ((float)digit * tens);
tens /= 10.0;
}
// if no places after decimal, stop now and return
if (places <= 0)
return;
// otherwise, write the point and continue on
UART1_Write(',');
for (i = 0; i < places; i++) {
tempfloat *= 10.0;
digit = (int) tempfloat;
UART1_Write(digit);
// once written, subtract off that digit
tempfloat = tempfloat - (float) digit;
}
}