I'm trying to get a PIC and Xmos to play nice using SPI but having no luck.
Master ---------------> Slave
PIC ---------------> XMOS
The PIC is programmed to send a byte over and the Xmos should Echo the byte (In the code below its not doing that cause I wanted to try send something constant)
I've plugged everything into an oscilloscope and looked at the waveform, the PIC (bless its cottons) works well and produces a nice lean waveform. The xmos chip on the other hand looks like its having tourettes.
the code i'm using is:
Code: Select all
void senddata(){
unsigned char data;
// data = 0b10101010;
while(1){
// start();
data = receive_byte();
// stop();
// start();
send_byte(data);
// stop();
}
}
int main()
{
setup();
senddata();
return 0;
}
Code: Select all
in port inputclk = XS1_PORT_1A;
in buffered port:8 mosi = XS1_PORT_1B;
out buffered port:8 miso = XS1_PORT_1C;
in port ss = XS1_PORT_1D;
clock clkblk = XS1_CLKBLK_1;
void setup()
{
configure_clock_src(clkblk, inputclk);
configure_in_port(mosi, clkblk);
configure_out_port(miso, clkblk, 1);
// configure_in_port_strobed_slave(mosi, ss, clkblk);
// configure_out_port_strobed_slave(miso, ss, clkblk, 0);
start_clock(clkblk);
set_clock_ready_src(clkblk, ss);
// set_port_inv(ss);
set_port_strobed(mosi);
set_port_strobed(miso);
set_port_slave(mosi);
set_port_slave(miso);
// start_clock(clkblk);
// ss when pinseq(0) :> void;
// inputclk when pinseq(0) :> void;
// clearbuf(miso);
// clearbuf(mosi);
}
void stop()
{
stop_clock(clkblk);
}
void start()
{
start_clock(clkblk);
}
unsigned char receive_byte()
{
unsigned char data;
clearbuf(miso);
clearbuf(mosi);
ss when pinseq(0) :> void;
//inputclk when pinseq(0) :> void;
mosi :> data;
return bitrev(data) >> 24;
}
void send_byte(unsigned char data)
{
clearbuf(miso);
clearbuf(mosi);
ss when pinseq(0) :> void;
//inputclk when pinseq(0) :> void;
miso <: 0b11001100;
mosi :> void;
//data;//(bitrev(data) >> 24);
}
Has anyone successfully managed to interface a PIC or an AVR with xmos as a slave??
Also I found that for some reason using the:
configure_in_port_strobed_slave(mosi, ss, clkblk);
configure_out_port_strobed_slave(miso, ss, clkblk, 0).
gave me a less stable result.
:?
Any help is appreciated,
Jake