Weird numbers
Lucky
Posts: 98
I'm trying to communicate with my MCP3208, but all the values that show up on the Debug screen look like weird symbols. I checked that the baud rate in the program and the baud rate on the terminal are the same. I used my oscilloscope to check the data in and out, and the clock and chip select. I calculated the expected value, and the 12 bits that are displayed on the oscilloscope match exactly what I expected(Vin= approx. 2.87V,
·value = 3560, so data in = 110111101000).I'm guessing there is some problem in my program as to reading the data in pin. Here is my program:
·value = 3560, so data in = 110111101000).I'm guessing there is some problem in my program as to reading the data in pin. Here is my program:
CON ADCclk = 12 ' ADCclk <------<P12 ADCdin = 13 ' ADCdout>------>P13 ADCdout = 14 ' ADCdin <------<P14 ADCcs = 15 ' ADCcs <------<P15 OBJ Debug : "FullDuplexSerial" PUB Control | dataIn Debug.start(31, 30, 0, 115200) dira[noparse][[/noparse]ADCclk..ADCcs] := %1011 outa[noparse][[/noparse]ADCclk..ADCcs] := %0000 repeat pulse(ADCcs) ShiftOut pulse(ADCclk) pulse(ADCclk) dataIn := ShiftIn waitcnt(1200 + cnt) debug.dec(dataIn) debug.str(string(", ")) PRI ShiftIn : dataIn | bitCount repeat bitCount from 0 to 11 dataIn |= ina[noparse][[/noparse]ADCdin] pulse(ADCclk) if bitCount < 11 dataIn <<= 1 return dataIn PRI ShiftOut | bitCount, mask, dataOut, begin mask := %1000_0000 dataOut := %0001_1000 begin := 0 repeat bitCount from 0 to 7 if begin == 1 if dataOut & mask outa[noparse][[/noparse]ADCdout]~~ pulse(ADCclk) else outa[noparse][[/noparse]ADCdout]~ pulse(ADCclk) else if dataOut & mask outa[noparse][[/noparse]ADCdout]~~ pulse(ADCclk) begin := 1 else outa[noparse][[/noparse]ADCdout]~ mask >>= 1 PRI Pulse(pin) outa[noparse][[/noparse]pin]~~ outa[noparse][[/noparse]pin]~
Comments
Assuming you have a 5MHz crystal attached to the Propeller's clock pins, put
at the beginning of your program.