Thank you for your reply Wim. I am trying to use SPI bus for the first time and these lines are helpful. What I have not figured out is how master writes to a specfic register address on the slave side. For instance how do we write 0x88, to a slave register, whose address is 0xC1? The CTRL1 register in the following code has an address of
Kind regards,
Hamid
- include "mbed.h"
- define STAT1 0x0
- define CTRL1 0x1
- define CTRL2 0x2
- define CTRL3 0x3
- define DATAR 0x4
- define CTRL1C 0x88
- define CTRL1R 0xC3
- define CTRL1W 0xC2
- define STAT1R 0xC1
function defintion
void calibrate11200(void);
void reset(void);
SPI spi(p11, p12, p13); mosi, miso, sclk
SPI spi(p5, p6, p7); mosi, miso, sclk
DigitalOut cs(p8);
Serial pc(USBTX, USBRX); tx, rx
int main()
{
Setup the spi for 8 bit data, high steady state clock,
second edge capture, with a 1MHz clock rate
spi.format(8,0); format ( # of bits, poloarti = 0,1,2,3)
spi.frequency(5000000); spi clock frequency 5MHz, T = 200 nS (ds, page 4)
reset();
while(1)
{
calibrate11200();
pc.printf(".......................begine whil loop here \n\r");
cs = 0; Select the device by seting chip select low
calibrate11200(); see calibration fun.
spi.write(STAT1R);
int stat1returns = spi.write(0x00);
pc.printf("STAT1 returned = 0x%X \r\n", stat1returns);
spi.write(CTRL1);
int CTRL1returns = spi.write(CTRL1C);
pc.printf("CTRL1 returned = 0x%X \r\n", CTRL1returns);
spi.write(DATAR);
int DATA1 = spi.write(0x00);
pc.printf("data1 register = 0x%X \r\n", DATA1);
pc.printf("\n\r.......................loop ended here \n\r");
cs = 1;
}
}
Hello,
I am trying to communicate with a NXP PN532 (nfc) through SPI. My first try was to use the spi class of mbed. Unfortunately the frame I have to send is a lot longer than 16 bits (the max allowed by void the function format( int bits,int mode = 0)) so it appears to me that I cannot use this class. Am I wrong? If so, Is there another solution?
Best regrads