hello,

here's the code in c.
Can you help me to port it into picbasic?
I am not sure how to read an address register and write an address register with some data.

void Write_SPI_Data(char address, char data)
{
ClrBit(PBDR, 2); //Chip select active
SPIDR = address;
while(!ValBit(SPISR,7)); //wait the end of tx
SPIDR=data;
while(!ValBit(SPISR,7)); //wait the end of tx
SetBit(PBDR, 2);//Chip select inactive
return;
}
char Read_SPI_Data(char address)
{
ClrBit(PBDR, 2); //Chip select active
SPIDR = address + 0x80; // "write addr" + 0x80 for reading operations
while(!ValBit(SPISR,7)); //wait the end of rx
SPIDR = 0x00; //dummy byte
while(!ValBit(SPISR,7)); //wait the end of rx
SetBit(PBDR, 2); //Chip select inactive
return SPIDR;
}
void Init_MEMS_device(void)
{
//Write_SPI_Data(0x20, 0xC7); // REG1 40Hz
Write_SPI_Data(0x20, 0xD7); // REG1 160Hz
Write_SPI_Data(0x21, 0x05); // REG2, data ready enabled, 16 bits
//Write_SPI_Data(0x21, 0x85); // REG2, data ready enabled, 16 bits. 6g FS
//Write_SPI_Data(0x21, 0x00); // REG2 //no DataRDY, 12 bit right just
Write_SPI_Data(0x22, 0x00); // REG3
Write_SPI_Data(0x38, 0x00); // DD_CFG
return;
}
void acquire(void)
{
ACC[0]=((Read_SPI_Data(0x29))<<8)|Read_SPI_Data(0x28);
ACC[1]=((Read_SPI_Data(0x2B))<<8)|Read_SPI_Data(0x2A);
ACC[2]=((Read_SPI_Data(0x2D))<<8)|Read_SPI_Data(0x2C);
return ;
}

-Thanks