Fix compilation errors

Fixed an invalid bit read and added a missing semicolon.
This commit is contained in:
Marco Vitchi Thulin 2024-03-10 16:42:23 +01:00
parent 12f1ce3e78
commit 660dd4e8de

123
main.c
View file

@ -14,20 +14,20 @@ void SendSPIDataADF4350 (uint32_t);
int main()
{
// set instructions to configure the ADF4350 for a 1 GHz +5dBm output
uint32_t ar0=0x500000;
uint32_t ar1=0x8008011;
uint32_t ar2=0x4e42;
uint32_t ar3=0x4b3;
uint32_t ar4=0xac803c;
uint32_t ar5=0x580005;
uint32_t ar0=0x500000;
uint32_t ar1=0x8008011;
uint32_t ar2=0x4e42;
uint32_t ar3=0x4b3;
uint32_t ar4=0xac803c;
uint32_t ar5=0x580005;
// alternative instructions for a 1001.25 MHz +5dBm output
//uint32_t ar0=0x500008;
//uint32_t ar1=0x8008029;
//uint32_t ar2=0x4e42;
//uint32_t ar3=0x4b3;
//uint32_t ar4=0xac803c;
//uint32_t ar5=0x580005;
//uint32_t ar0=0x500008;
//uint32_t ar1=0x8008029;
//uint32_t ar2=0x4e42;
//uint32_t ar3=0x4b3;
//uint32_t ar4=0xac803c;
//uint32_t ar5=0x580005;
// set direction of PB1 (DO) and PB2 (USCK) as output
DDRB=(1<<PB1)|(1<<PB2);
@ -39,68 +39,69 @@ int main()
// set direction of PB4 (status LED) as output
DDRB |= (1 << PB4);
// set direction of PB3 (LE) as open-drain output
DDRB |= (1 << PB3);
// set direction of PB3 (LE) as open-drain output
DDRB |= (1 << PB3);
// set PB3 (LE) low
PORTB &= ~(1 << PORTB3);
// set PB3 (LE) low
PORTB &= ~(1 << PORTB3);
// set direction of PB5 (LD Input) as input
// set direction of PB5 (LD Input) as input
DDRB &= ~(1 << DDB0);
// enable pull-up resistor on PB5
// enable pull-up resistor on PB5
PORTB |= (1 << PORTB5);
// flash the Status LED (PB4) to show that everything works
PORTB |= (1 << PORTB4);
Delay(500000);
PORTB &= ~(1 << PORTB4);
Delay(100000);
// flash the Status LED (PB4) to show that everything works
PORTB |= (1 << PORTB4);
Delay(500000);
PORTB &= ~(1 << PORTB4);
Delay(100000);
// enter loop waiting for frequency lock to be achieved
while (1)
{
// read the state of LD (PB5)
uint8_t ldState = PINB & (1 << PINB5);
// enter loop waiting for frequency lock to be achieved
while (1)
{
// read the state of LD (PB5)
uint8_t ldState = PINB & (1 << PINB5);
// if LD is low, turn on the LED (PB4)
if (ldState == 0)
PORTB |= (1 << PORTB4); // Turn on the LED
else
PORTB &= ~(1 << PORTB4); // Turn off the LED
}
// if LD is low, turn on the LED (PB4)
if (ldState == 0)
PORTB |= (1 << PORTB4); // Turn on the LED
else
PORTB &= ~(1 << PORTB4); // Turn off the LED
}
}
// general purpose delay
void Delay(uint32_t tmax)
{
uint32_t i;
for (i=0;i < tmax ; i++)
{
asm("nop");
}
uint32_t i;
for (i=0;i < tmax ; i++)
{
asm("nop");
}
}
// send an 8 bit word via SPI1 and receive an 8 bit word at the same time
uint8_t SendReceiveSPIData(uint8_t value)
{
uint8_t lout = 0;
uint8_t lout = 0;
short int i=0;
// prob change the 8 below to len of value?
for(i=0;i<8;i++)
{
USIDR=value[i]; // write data bytes in Data register, will cause them to get sent on clock
///USIDR = value[i]; // wrong way to do it apparently, still saving for future reference
USIDR = (value >> i) & 0x01; // write data bytes in Data register, will cause them to get sent on clock
while(USIOIF==0) // check USI data counter overflow flag to detect the end of transmission every byte
{
USICR|=(1<<USICLK)|(1<<USITC); // enable clock for transmission and generate clock for slave deivce
}
USISR|=(1<<USIOIF) // clear USI data counter overflow flag
USISR|=(1<<USIOIF); // clear USI data counter overflow flag
}
// Read in a 16 bit frame
///uint16_t inbyte = *(uint32_t *)(SPI1_BASE + 0x0c);
//return inbyte;
///uint16_t inbyte = *(uint32_t *)(SPI1_BASE + 0x0c);
//return inbyte;
}
// send a 32 bit register value to the ADF4350
@ -112,26 +113,26 @@ void SendSPIDataADF4350 (uint32_t outval)
uint8_t byte3 = (outval & 0x0000FF00) >> 8;
uint8_t byte4 = outval & 0x000000FF;
// send these to the ADF4350 via SPI
SendReceiveSPIData (byte1);
SendReceiveSPIData (byte2);
// send these to the ADF4350 via SPI
SendReceiveSPIData (byte1);
SendReceiveSPIData (byte2);
SendReceiveSPIData (byte3);
SendReceiveSPIData (byte4);
// 2 x 16 version:
// split into 2 x 16 bit words
// 2 x 16 version:
// split into 2 x 16 bit words
///uint16_t highWord = (outval & 0xffff0000) >> 16;
///uint16_t lowWord = outval & 0x0000ffff;
// send these to the ADF4350 via SPI
///SendReceiveSPIData (highWord);
///SendReceiveSPIData (lowWord);
///uint16_t lowWord = outval & 0x0000ffff;
// send these to the ADF4350 via SPI
///SendReceiveSPIData (highWord);
///SendReceiveSPIData (lowWord);
// delay so the clock has gone low before LE is taken high
Delay(10);
// pull LE high to load the data into the ADF4350 register
PORTB |= (1 << PORTB3);
// short delay while LE is high (minimum of 20ns)
Delay(30);
// pull LE low again
PORTB &= ~(1 << PORTB3);
// delay so the clock has gone low before LE is taken high
Delay(10);
// pull LE high to load the data into the ADF4350 register
PORTB |= (1 << PORTB3);
// short delay while LE is high (minimum of 20ns)
Delay(30);
// pull LE low again
PORTB &= ~(1 << PORTB3);
}