spi read from an arduino program
-
- Posts: 175
- Joined: Thu Feb 04, 2010 7:44 am
- Has thanked: 3 times
- Been thanked: 3 times
- Contact:
spi read from an arduino program
Hi.
Could this be converted to a flowcode chart??
uchar Read_MFRC522(uchar addr)
{uchar val;digitalWrite(chipSelectPin, LOW);
//address format:1XXXXXX0
SPI.transfer(((addr<<1)&0x7E) | 0x80);
val =SPI.transfer(0x00);
digitalWrite(chipSelectPin, HIGH);
return val;
I dont understand where return val is pulled from????
Could this be converted to a flowcode chart??
uchar Read_MFRC522(uchar addr)
{uchar val;digitalWrite(chipSelectPin, LOW);
//address format:1XXXXXX0
SPI.transfer(((addr<<1)&0x7E) | 0x80);
val =SPI.transfer(0x00);
digitalWrite(chipSelectPin, HIGH);
return val;
I dont understand where return val is pulled from????
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: spi read from an arduino program
Hello,
Yes this looks fairly simple to achieve. Which version of Flowcode are you wanting to use?
Yes this looks fairly simple to achieve. Which version of Flowcode are you wanting to use?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 175
- Joined: Thu Feb 04, 2010 7:44 am
- Has thanked: 3 times
- Been thanked: 3 times
- Contact:
Re: spi read from an arduino program
Do you understand where the return val variable is being loaded from??
-
- Posts: 175
- Joined: Thu Feb 04, 2010 7:44 am
- Has thanked: 3 times
- Been thanked: 3 times
- Contact:
Re: spi read from an arduino program
Im not at a computer so cant test this yet but i wanted to see if this looks right.cobra1 wrote:Hi.
Could this be converted to a flowcode chart??
uchar Read_MFRC522(uchar addr)
{uchar val;digitalWrite(chipSelectPin, LOW);
//address format:1XXXXXX0
SPI.transfer(((addr<<1)&0x7E) | 0x80);
val =SPI.transfer(0x00);
digitalWrite(chipSelectPin, HIGH);
return val;
I dont understand where return val is pulled from????
CS = Low
addr = 0x14
Spidata = (((addr<<1)&0x7E) | 0x80);
SEND SPI BYTE (Spidata)
RECEIVE SPI BYTE (Val) not sure why the origional has 0x00
Return Val = Val
CS = High
Does this look like it will work??
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: spi read from an arduino program
Hello,
Yep that looks spot on.
Yep that looks spot on.
A SPI transaction simultaneously transfers and receives a byte at the same time. Generally you only want to be able to read or write at any one time so the Flowcode macros mask off the surplus value to make things more straightforward. In your case the 0x00 is being sent when calling the receive macro but really it could be anything as it is the incoming value you are interested in.RECEIVE SPI BYTE (Val) not sure why the origional has 0x00
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 175
- Joined: Thu Feb 04, 2010 7:44 am
- Has thanked: 3 times
- Been thanked: 3 times
- Contact:
Re: spi read from an arduino program
Thanks for clearing that up ben. Will see if it works when i get home
-
- Posts: 175
- Joined: Thu Feb 04, 2010 7:44 am
- Has thanked: 3 times
- Been thanked: 3 times
- Contact:
Re: spi read from an arduino program
I have another question...
How would you deal with this?
WRITE_SPI (Register, Temp | Mask)
and also
WRITE_SPI (Register, Temp & (~Mask))
Mask = 0x80
Temp is a byte read from a read function.
I havnt done masking before so this is a bit new to me.
How would you deal with this?
WRITE_SPI (Register, Temp | Mask)
and also
WRITE_SPI (Register, Temp & (~Mask))
Mask = 0x80
Temp is a byte read from a read function.
I havnt done masking before so this is a bit new to me.
-
- Posts: 1314
- Joined: Sun Jan 15, 2012 3:15 pm
- Has thanked: 474 times
- Been thanked: 458 times
- Contact:
Re: spi read from an arduino program
Hi Cobra
Could you post the arduino code in a code box as it might make it easier to help
Regards
Dazz
Could you post the arduino code in a code box as it might make it easier to help
Regards
Dazz
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php
-
- Posts: 175
- Joined: Thu Feb 04, 2010 7:44 am
- Has thanked: 3 times
- Been thanked: 3 times
- Contact:
Re: spi read from an arduino program
Code: Select all
* Function:SetBitMask
* Description:set RC522 register bit
* Input parameter:reg--register address;mask--value
* Return:null
*/
void SetBitMask(uchar reg, uchar mask)
{
uchar tmp;
tmp = Read_MFRC522(reg);
Write_MFRC522(reg, tmp | mask); // set bit mask
}
/*
* Function:ClearBitMask
* Description:clear RC522 register bit
* Input parameter:reg--register address;mask--value
* Return:null
*/
void ClearBitMask(uchar reg, uchar mask)
{
uchar tmp;
tmp = Read_MFRC522(reg);
Write_MFRC522(reg, tmp & (~mask)); // clear bit mask
}