main.c
115 lines
| 2.5 KiB
| text/x-c
|
CLexer
r47 | #include <stdio.h> | |||
#include <gpio.h> | ||||
#include <uart.h> | ||||
#include <stm32f4xx.h> | ||||
#include <bsp.h> | ||||
#include <core.h> | ||||
#include <spi.h> | ||||
void ads1278readOut(spi_t spidev,int32_t* data) | ||||
{ | ||||
gpioset(ADC_FSYNC); | ||||
r58 | //delay_100us(1); | |||
for(volatile int i=0;i<50;i++); | ||||
r47 | gpioclr(ADC_FSYNC); | |||
for(int i=0;i<8;i++) | ||||
{ | ||||
data[i]=spigetw(spidev)<<16; | ||||
data[i]+=spigetw(spidev)<<8; | ||||
data[i]+=spigetw(spidev); | ||||
if((data[i]&(1<<23)))data[i]-=(1<<24); | ||||
} | ||||
} | ||||
void pushData(int32_t* data) | ||||
{ | ||||
r58 | // printf("%f\t%f\t%f\n",(6.0/(8*1000*1000)) *data[0],(6.0/(8*1000*1000))*data[1],(6.0/(8*1000*1000))*data[2]); | |||
printf("%f\n",(6.0/(16*1000*1000)) *data[0]); | ||||
} | ||||
void pushData2(int32_t* data) | ||||
{ | ||||
char buffer[29]; | ||||
buffer[0] = 0xa5; | ||||
buffer[1] = 0x0f; | ||||
buffer[2] = 0x00; | ||||
buffer[27] = 0xf0; | ||||
buffer[28] = 0x5a; | ||||
for(int i=0;i<8;i++) | ||||
{ | ||||
buffer[(i*3)+3] = (char)data[i]>>16; | ||||
buffer[(i*3)+4] = (char)data[i]>>8; | ||||
buffer[(i*3)+5] = (char)data[i]; | ||||
} | ||||
uartputnc(uart1,buffer,29); | ||||
r47 | } | |||
r58 | void sample() | |||
{ | ||||
int32_t data[8]; | ||||
data[0]=0x712345; | ||||
char buffer[2+1+3+2]; | ||||
buffer[0] = 0xa5; | ||||
buffer[1] = 0x0f; | ||||
buffer[2] = 0x00; | ||||
buffer[2+1+3] = 0xf0; | ||||
buffer[2+1+4] = 0x5a; | ||||
while(1) | ||||
{ | ||||
//uartputnc(uart1,buffer,3); | ||||
uartputc(uart1,0xa5); | ||||
uartputc(uart1,0x0f); | ||||
uartputc(uart1,0x01); | ||||
uartputc(uart1,25); | ||||
for(int i=0;i<8;i++) | ||||
{ | ||||
//ads1278readOut(spi1,data); | ||||
uartputc(uart1,(char)0x1);//(data[0])>>16); | ||||
uartputc(uart1,(char)0x2);//(data[0]>>8)); | ||||
uartputc(uart1,(char)0x3);//(data[0]>>0)); | ||||
} | ||||
uartputc(uart1,0xf0); | ||||
uartputc(uart1,0x5a); | ||||
} | ||||
} | ||||
r47 | ||||
r78 | int libuc_main() | |||
r47 | { | |||
int32_t data[8]; | ||||
r58 | char test=0; | |||
for(int i=0;i<500;i++) | ||||
{ | ||||
ads1278readOut(spi1,data); | ||||
delay_100us(10); | ||||
} | ||||
sample(); | ||||
//while(1) | ||||
//{ | ||||
// uartputc(uart1,test++); | ||||
//} | ||||
r47 | ||||
r58 | // while(1) | |||
// { | ||||
// ads1278readOut(spi1,data); | ||||
// gpioclr(LED2); | ||||
// //delay_100us(100); | ||||
//// for(volatile int i=0;i<100;i++); | ||||
// pushData(data); | ||||
// gpioset(LED2); | ||||
// //delay_100us(100); | ||||
// } | ||||
r47 | } | |||
r58 | ||||