Created Sat, 14 Apr 2012 03:04:07 +0000 by micronut
Sat, 14 Apr 2012 03:04:07 +0000
I am new to the MPIDE and I am trying to interface the UNO32 to a Parallax Propeller chip via SPI, The Propeller uses a 100kHz bitbang SPI slave and I'm trying to use DSPI. I have a couple of questions:
#include <DSPI.h>
DSPI0 spi;
void
setup(){
spi.begin();
spi.setSpeed(100000);
}
void
loop(){
spi.setSelect(LOW);
Delay10us();
spi.transfer(0x04);
Delay10us();
spi.transfer(0x00);
Delay10us();
spi.transfer(0x00);
Delay10us();
spi.setSelect(HIGH);
while(true){}
}
void
Delay10us()
{
volatile int cnt;
for (cnt = 0; cnt < 100; cnt++) {
}
}
Thanks!
Mon, 16 Apr 2012 02:06:27 +0000
I mistakenly thought the Ardiuno Library would use the formula of System Clock/128 or 80MHz/128 but looking at the header code I see it uses the 16MHz just like the Arduino so the result would be 16MHz/128 or 125 KHz which I am pretty sure will work with the propeller. If so I'm just going to use the SPI library so my code can easly port over to the Arduino.
Sun, 29 Apr 2012 03:53:34 +0000
hello
i have a question about usuing the dspi library, basiclly, im looking to transfer 16 bits of data from a adc chip. here's the code for it, which works great! but their must be a better way. i looked in the dspi reference guide, but it didn't work :(
Philip
byte1 = spi.transfer(0x00); //transfer (read) 8 bits from the adc chip
byte2 = spi.transfer(0x00); //transfer (read) the second 8 bits. now we have our 16 bits
adcvalue = (byte1 << 8 ) | (byte2 & 0xff);
Wed, 02 May 2012 00:20:16 +0000
Hello,
You could do it like this if you wanted to:
uint8_t rgbRcv[2];
uint8_t rgbSnd[2] = {0x00, 0x00};
uint16_t adcvalue;
spi.transfer(2, rgbSnd, rgbRcv);
adcvalue = (rgbRcv[0] << 8) | (rgbRcv[1] & 0xFF);
Then you won't have multiple calls of transfer in the sketch. It'll do it automatically.
void transfer(uint16_t cbReq, uint8_t * pbSnd, uint8_t * pbRcv);
cbReq = Count of Bytes Requested pbSnd = Pointer to Bytes to Send pbRcv = Pointer to Bytes to Receive
--just to get you a little familiar with the naming conventions.
Best Regards, Ryan K Digilent