How do i do a bit read

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User14262
Level 2
Level 2
Hey people i have a problem im from ardiuno ide and moved to dave which is 100% better but my prpblem seem to be bit read set and modify a individual bit how do i do that with dave?
Reading Bits and setting individual Bits is what i wanna do thats my question i see in ardiuno they have bitread() can i use that? bitRead(x, n) would the x beconsider the register i wanna access and n would be the specific bit right i wanna read ??? How can i apply this to dave. Also i notice dave has spi recieve is that the same as reading a byte?
0 Likes
7 Replies
User14262
Level 2
Level 2
void setup ()
{
int pin_ign5;
uint8_t data = 0;
int datarecieve;
status = DAVE_Init(); // SPI_MASTER_Init() is called from DAVE_Init()
if(status == DAVE_STATUS_SUCCESS)
{
data = ((IN_STAT_COMP)>>24);//Input Enable Register Go /* Send 4th byte of 32bit start address */ need to read
SPI_MASTER_EnableSlaveSelectSignal(&SPI_MASTER_0, SPI_MASTER_SS_SIGNAL_0);
SPI_MASTER_Transmit(&SPI_MASTER_0, &data, 1);
while(SPI_MASTER_0.runtime->tx_busy);
datarecieve=bitRead(IN_STAT_COMP,4);
if (datarecieve == 0x01 )
{
pin_ign5=true;
SPI_MASTER_DisableSlaveSelectSignal(&SPI_MASTER_0);
}
}


IN_STAT_COMP is the resister i wanna access like the code above bits (32-24)
datarecieve is the bit read im trying to use just like ardiuno can this work like above code?
also when i wanna read IN_STAT_COMP do i spi transmit like above code then use the bitread()?
aslo is spi recieve the same has reading a byte but can i also read a bit within a byte does dave have this somewhere?

these are from the ardiuno header can i use this in dave also?
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))


or can i use this
#define BitVal(data,y) ( (data>>y) & 1) /** Return Data.Y value **/
#define SetBit(data,y) data |= (1 << y) /** Set Data.Y to 1 **/
#define ClearBit(data,y) data &= ~(1 << y) /** Clear Data.Y to 0 **/
#define TogleBit(data,y) (data ^=BitVal(y)) /** Togle Data.Y value **/
#define Togle(data) (data =~data ) /** Togle Data value **/

and a example
uint8_t number = 0x05; //0b00000101
uint8_t bit_2 = BitVal(number,2); // bit_2 = 1
uint8_t bit_1 = BitVal(number,1); // bit_1 = 0

SetBit(number,1); // number = 0x07 => 0b00000111
ClearBit(number,2); // number =0x03 => 0b0000011
0 Likes
User14262
Level 2
Level 2
could this work?????

void readign5()
{
uint32_t tmp;
uint8_t data = 0;
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
int datarecieve=0;
uint32_t status1 = 0;
uint32_t status2 = 0;
SPI_MASTER_EnableSlaveSelectSignal(&SPI_MASTER_0, SPI_MASTER_SS_SIGNAL_0);
/* Clear the flags */
SPI_MASTER_ClearFlag(&SPI_MASTER_0,XMC_SPI_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION);
SPI_MASTER_ClearFlag(&SPI_MASTER_0,XMC_SPI_CH_STATUS_FLAG_RECEIVE_INDICATION);
if(status == DAVE_STATUS_SUCCESS)
{
/*Load the command*/
data = IN_STAT_COMP;//bits 31-24
/* Send the read status register command to SPI flash chip */
SPI_MASTER_Transmit(&SPI_MASTER_0, &data, 1);
while(SPI_MASTER_0.runtime->tx_busy);
/* Wait till dummy data is received from chip */
do
{//GET STATUS
status1 = SPI_MASTER_GetFlagStatus(&SPI_MASTER_0,XMC_SPI_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION);
status2 = SPI_MASTER_GetFlagStatus(&SPI_MASTER_0,XMC_SPI_CH_STATUS_FLAG_RECEIVE_INDICATION);
}
while(((status1 == 0) && (status2 == 0)));
/* Clear the flags */
SPI_MASTER_ClearFlag(&SPI_MASTER_0,XMC_SPI_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION);
SPI_MASTER_ClearFlag(&SPI_MASTER_0,XMC_SPI_CH_STATUS_FLAG_RECEIVE_INDICATION);
/* Receive the status command from the SPI flash chip */
SPI_MASTER_Receive(&SPI_MASTER_0,&tmp, 1);
while(SPI_MASTER_0.runtime->rx_busy);
datarecieve=bitRead(tmp,4);//READ BIT 4 WHICH IS IGN5 // I ONLY WANT TO READ BIT 4 BACK TO SEE IF ITS A TRUE==1 OR FALSE==0
SPI_MASTER_DisableSlaveSelectSignal(&SPI_MASTER_0);
if (datarecieve == 0x01 )
{
pin_ign5=true;
}
else if (datarecieve == 0x00 )
{
pin_ign5=false;
}
}
return pin_ign5;
}
0 Likes
User14262
Level 2
Level 2
Can someone answer my questions
0 Likes
User14262
Level 2
Level 2
Really over a 100 view and not a single respond
0 Likes
User14262
Level 2
Level 2
Really over a 200 view and not a single respond
0 Likes
User14262
Level 2
Level 2
Really over a 300 view and not a single respond????? does infineon stand behind there product or not
0 Likes
User14262
Level 2
Level 2
IS THIS THE RIGHT WAY??????????


int readign5()
{
DAVE_STATUS_t status;
status = DAVE_Init(); // SPI_MASTER_Init() is called from DAVE_Init()
uint8_t tmp[3];
uint8_t data = 0;
int pin_ign5;
int datarecieve=0;
uint32_t status1 = 0;
uint32_t status2 = 0;
SPI_MASTER_EnableSlaveSelectSignal(&SPI_MASTER_0, SPI_MASTER_SS_SIGNAL_0);
/* Clear the flags */
SPI_MASTER_ClearFlag(&SPI_MASTER_0,XMC_SPI_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION);
SPI_MASTER_ClearFlag(&SPI_MASTER_0,XMC_SPI_CH_STATUS_FLAG_RECEIVE_INDICATION);
if(status == DAVE_STATUS_SUCCESS)
{
/*Load the command*/
data = (0 & IN_STAT_COMP);//bits 31-24 //READ COMMAND
/* Send the read status register command to SPI flash chip */
SPI_MASTER_Transmit(&SPI_MASTER_0, &data, 1);
while(SPI_MASTER_0.runtime->tx_busy);
/* Wait till dummy data is received from chip */
do
{//GET STATUS
status1 = SPI_MASTER_GetFlagStatus(&SPI_MASTER_0,XMC_SPI_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION);
status2 = SPI_MASTER_GetFlagStatus(&SPI_MASTER_0,XMC_SPI_CH_STATUS_FLAG_RECEIVE_INDICATION);
}
while(((status1 == 0) && (status2 == 0)));
/* Clear the flags */
SPI_MASTER_ClearFlag(&SPI_MASTER_0,XMC_SPI_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION);
SPI_MASTER_ClearFlag(&SPI_MASTER_0,XMC_SPI_CH_STATUS_FLAG_RECEIVE_INDICATION);
/* Receive the status command from the SPI flash chip */
SPI_MASTER_Receive(&SPI_MASTER_0,tmp,3);
while(SPI_MASTER_0.runtime->rx_busy);
datarecieve=bitRead(tmp[3],4);//READ BIT 4 WHICH IS IGN5 // I ONLY WANT TO READ BIT 4 BACK TO SEE IF ITS A TRUE==1 OR FALSE==0
SPI_MASTER_DisableSlaveSelectSignal(&SPI_MASTER_0);
}
if (datarecieve == 0x01 )
{
pin_ign5=1;
}
else if (datarecieve == 0x00 )
{
pin_ign5=0;
}
return pin_ign5;
}
0 Likes