Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem using the SPI library
09-01-2014, 05:20 PM,
#1
Problem using the SPI library
Hi,
The short piece of code below will only execute to the end, ( confirmed by a scope on pin2 D2 ), if I comment-out the SPI.transfer instructions as shown. Compiling and upload operations complete successfully. My setup is ide rev 903x4, diy 20MHz 4550 board, bootloader 413.

Can anyone see the problem ?
Is there a mistake with my use of SPI library syntax ? Bugs in SPI library ?
There is little guidance on the language reference pages which are quite bare and incomplete.

My application is to send a frequency/phase/control word to a DDS chip using SPI.

regards,
Spacerowa.


//include SPI library
#include <SPI.h>

//assign pins
#define FQUD 2 //use pin2 D2, chip pin 35 as FQUD

void setup() //runs once only
{
pinMode(FQUD, OUTPUT);
SPI.setClockDivider(SPI_CLOCK_DIV4);
SPI.setDataMode(SPI_MODE1);
SPI.begin; //start the library
}

void loop() //runs for ever
{
//SPI.transfer(0x40); //MSB
//SPI.transfer(0x02);
//SPI.transfer(0x0C);
//SPI.transfer(0x49);
//SPI.transfer(0xBA); //LSB

digitalWrite(FQUD, HIGH); //take high to end serial load & update dds registers
delay(50);
digitalWrite(FQUD, LOW); //return to idle state

while (1){ //do nothing for ever
}
}
Reply
09-01-2014, 08:40 PM,
#2
RE: Problem using the SPI library
(09-01-2014, 05:20 PM)Spacerowa Wrote: Hi,
The short piece of code below will only execute to the end, ( confirmed by a scope on pin2 D2 ), if I comment-out the SPI.transfer instructions as shown. Compiling and upload operations complete successfully. My setup is ide rev 903x4, diy 20MHz 4550 board, bootloader 413.

Can anyone see the problem ?
Is there a mistake with my use of SPI library syntax ? Bugs in SPI library ?
There is little guidance on the language reference pages which are quite bare and incomplete.

My application is to send a frequency/phase/control word to a DDS chip using SPI.

regards,
Spacerowa.


//include SPI library
#include <SPI.h>

//assign pins
#define FQUD 2 //use pin2 D2, chip pin 35 as FQUD

void setup() //runs once only
{
pinMode(FQUD, OUTPUT);
SPI.setClockDivider(SPI_CLOCK_DIV4);
SPI.setDataMode(SPI_MODE1);
SPI.begin; //start the library
}

void loop() //runs for ever
{
//SPI.transfer(0x40); //MSB
//SPI.transfer(0x02);
//SPI.transfer(0x0C);
//SPI.transfer(0x49);
//SPI.transfer(0xBA); //LSB

digitalWrite(FQUD, HIGH); //take high to end serial load & update dds registers
delay(50);
digitalWrite(FQUD, LOW); //return to idle state

while (1){ //do nothing for ever
}
}
Did you look at the example zigbee.pde in folder Examples\04- communication\spi ?
I don't see in your code the definition of the SPI pins (CS SDO SDI CLK).

I used recently the SPI library to communicate with a SD card and to exchange between a 18f4550 as master and another one as slave.
It works !
Reply
10-01-2014, 01:26 PM,
#3
RE: Problem using the SPI library
Hi Gtcbreizh,
Thanks for the suggestion. I will do it and define the other spi pins also. I looked at the other two example projects but not the zigbee one.
Instead I used my previous experience with spi on the Arduino platform; but seems are large syntax differences.
If only more guidance in the Pinguino language reference pages and I would not have needed to post to the forum.
Reply
10-01-2014, 03:38 PM,
#4
RE: Problem using the SPI library
(10-01-2014, 01:26 PM)Spacerowa Wrote: Hi Gtcbreizh,
Thanks for the suggestion. I will do it and define the other spi pins also. I looked at the other two example projects but not the zigbee one.
Instead I used my previous experience with spi on the Arduino platform; but seems are large syntax differences.
If only more guidance in the Pinguino language reference pages and I would not have needed to post to the forum.

I agree that the documentation relating spi is poor. But you have to undestand that the subjects are very very various, the microcontrollers 8 or 32 bits also and the users are coming from very, very various horizons.
Even with Arduino the documentation is very far from being perfect !
Each one has to give a bit to improve the situation and don't stay a pure consumer !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)