How do you debug SPI?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How do you debug SPI?

648件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Mike45 on Mon Nov 08 10:20:13 MST 2010
I am trying to interface to an ADC chip - MCP3002.  I've read the data sheet many times and tried to follow the directions with no success and i don't know what to try next. 

While turning my pot seems to get me a range of values from 0 to 1023, they are extremely inaccurate.  I get better values near 0 and 1023, but other values can be off by 3 or 400.  My code simply writes a configuration byte(0x1E) and trys to do a read like this:

void readandwrite (void)
{

GPIOSetValue( PORT0, 2, 1 );
  /* port0, bit 2 is set to GPIO output and high */
GPIOSetValue( PORT0, 2, 0 );

SSPSend ((uint8_t *)LIST, 1); //#define LIST 0x1E

SSPReceive ((uint32_t  *)src_addr, 1);
GPIOSetValue( PORT0, 2, 1 );

printf("%i\n", src_addr[0]);

}



The only other changes i made to the code was to output a 10 bit value and change the SCK frequency to 1007 HZ by setting LPC_SSP_>CPSR t0 0xFE and LPC_SSP_>CR0 to 0x7C09.

Any suggestions on how to debug SPI would be greatly appreciated.

Thanks,
0 件の賞賛
返信
3 返答(返信)

634件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Mike45 on Mon Nov 08 15:50:40 MST 2010
i still get huge errors using 16 bits
0 件の賞賛
返信

634件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Mon Nov 08 12:45:45 MST 2010
Why don't you set SPI word length to 16 bits?
0 件の賞賛
返信

634件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Mike45 on Mon Nov 08 12:08:45 MST 2010
I think that I am getting close, i am doing two sequential reads,  but i don't know how to process the MSB and LSB values i am getting into an integer.  [IMG]http://i52.tinypic.com/24pe1k5.png[/IMG]
0 件の賞賛
返信