Part Number: AM3358
Other Parts Discussed in Thread: ADS8860
Tool/software: Linux
Hi,
i'm very new in embedded systems, and i'm working with beaglebone black rec C, so i'm reading data from an ADC (ads8860) from the SPI0, and send the data to a software via UARTx everything is ok, but now i need to implement a timer interrupt to read the values from the adc, every 2us (500 kHz).
Currently, i'm working from Putty, building in Python, but i can do in C# too.
The line of code in def read_adc-> time.sleep(0.000002) doesnt do what i want, thats why i need a timer interrupt.
Code:
#libs
import time
import spidev
import serial
import Adafruit_BBIO.UART as UART
#config UART
UART.setup("UART1")
disp = serial.Serial(port ="/dev/ttyO1", baudrate = 115200 )
#configs SPI
spi = spidev.SpiDev()
spi.open(1,0)
spi.max_speed_hz = 24000000
spi.mode = 1
spi.lsbfirst = False
spi.threewire = False
spi.cshigh = True
#configs rs232
global msb,lsb
global NA
def read_adc():
a = spi.readbytes(2)
msb = a[0]
lsb = a[1]
time.sleep(0.000002)
#b = 256 * msb + lsb
#c = float(int(b)*5) / 65535
#print c,'V'
def send_data():
disp.write('D')
disp.write('L')
count_na = 0
while True:
read_adc()
disp.write(msb)
disp.write(lsb)
count_na = count_na + 1
if count_na == NA:
break
def protocol():
while True:
buffer = disp.read(1)
count = 0
if count == 0:
if str(buffer) == 'I' | str(buffer) == 'R':
count == 1
print 'Recebeu:', buffer
if count == 1:
if str(buffer) == 'N':
print 'Recebeu:',buffer
count = count + 1
if str(buffer) == 'T':
print 'Recebeu:',buffer
count = 0
if count == 2:
FA = buffer
count = count + 1
print 'FA = ',FA
if count == 3:
NA = buffer
print 'NA = ',NA
send_data()
count = 0
while True:
protocol()
device tree to SPI0:
elinux.org/BeagleBone_Black_Enable_SPIDEV
Any help will be aprecciate.
Best Regards,
David