Exemplo n.º 1
0
/*****************************************************************************
** Function name:		SPI_SendRcv_with_bit_length
**
** Descriptions:		Send a block of data to the SPI port, the
**									first parameter is the buffer pointer, the 2nd
**									parameter is the bit length.
**
** parameters:			slave select, buffer pointer, and the block length
** Returned value:		None
** note:                user defined (not official driver)
*****************************************************************************/
void SPI_SendRcv_with_bit_length( LPC_SPI_TypeDef *SPIx, SLAVE_t slave, uint16_t *tx, uint16_t *rx, uint32_t bitLength )
{

#if SPI_INTERRUPT
		while(!txrdy);
		txrdy = 0;
		/* Set frame length to fixed 8 for now. */
		SPIx->TXDATCTL = /*TXDATCTL_SSELN(slave) |*/ TXDATCTL_FSIZE(bitLength - 1) | TXDATCTL_EOT | *tx;
		SPIx->INTENSET = STAT_TXRDY;
		while(!rxrdy);
		rxrdy = 0;
		*rx = SPIx->RXDAT;
#if STALL_ENABLE
		SPIx->INTENSET = STAT_RXRDY | STAT_CLKSTALL;
#else
		SPIx->INTENSET = STAT_RXRDY;
#endif
#else
		while ( (SPIx->STAT & STAT_TXRDY) == 0 );
		/* Set frame length to fixed 8 for now. */
		SPIx->TXDATCTL = /*TXDATCTL_SSELN(slave) |*/ TXDATCTL_FSIZE(bitLength - 1) | TXDATCTL_EOT | *tx;
		while ( (SPIx->STAT & STAT_RXRDY) == 0 );
		*rx = SPIx->RXDAT;
#endif
		return;

}
Exemplo n.º 2
0
/*****************************************************************************
** Function name:		SPI_SlaveSend
**
** Descriptions:		Send a block of data to the SPI port, the 
**						first parameter is the buffer pointer, the 2nd 
**						parameter is the block length.
**
** parameters:			buffer pointer, and the block length
** Returned value:		None
** 
*****************************************************************************/
void SPI_SlaveSend( LPC_SPI_TypeDef *SPIx, uint8_t *tx, uint32_t Length )
{
  uint32_t i = 0;

  while ( i < Length ) {
#if SPI_INTERRUPT
		while(!txrdy);
		txrdy = 0;
		/* Set frame length to fixed 8 for now. */
		if ( i == 0 ) {
			SPIx->TXDATCTL = TXDATCTL_FSIZE(SLAVE_FRAME_SIZE) | TXDATCTL_RX_IGNORE | *tx++;
		}
		else {
			SPIx->TXDAT = *tx++;
		}
		SPIx->INTENSET = STAT_TXRDY;
#else
		/* Move only if TXRDY is ready */
		while ( (SPIx->STAT & STAT_TXRDY) == 0 );
		/* Set frame length to fixed 8 for now. */
		if ( i == 0 ) {
			SPIx->TXDATCTL = TXDATCTL_FSIZE(SLAVE_FRAME_SIZE) | TXDATCTL_RX_IGNORE | *tx++;
		}
		else {
			SPIx->TXDAT = *tx++;
		}
#endif
		i++;
  }
  return; 
}
Exemplo n.º 3
0
/*****************************************************************************
** Function name:		SPI_SlaveReceive
** Descriptions:		the module will receive a block of data from 
**						the SPI, the 2nd parameter is the block length.
** parameters:			buffer pointer, and block length
** Returned value:		None
** 
*****************************************************************************/
void SPI_SlaveReceive( LPC_SPI_TypeDef *SPIx, uint8_t *rx, uint32_t Length )
{
  uint32_t i = 0;

  /* Set frame length to fixed 8 for now. */
  SPIx->TXCTRL = TXDATCTL_FSIZE(SLAVE_FRAME_SIZE);
  while ( i < Length )
  {
#if SPI_INTERRUPT
		while(!rxrdy);
		rxrdy = 0;
		*rx++ = SPIx->RXDAT;
#if STALL_ENABLE
		SPIx->INTENSET = STAT_RXRDY | STAT_CLKSTALL;
#else
		SPIx->INTENSET = STAT_RXRDY;
#endif
#else
		/* Read only if RX data is available. */
		while ( (SPIx->STAT & STAT_RXRDY) == 0 );
		*rx++ = SPIx->RXDAT;
#endif
		i++;
  }
  return; 
}
Exemplo n.º 4
0
void NRF24_InsWrite(uint8_t instruction,const uint8_t *pbuff,uint32_t num){
	NRF24_Enable();

	/* transfer instruction*/
	while((LPC_SPI0->STAT& STAT_TXRDY) == 0);
	LPC_SPI0->TXDATCTL = TXDATCTL_FSIZE(8-1) | TXDATCTL_EOT | TXDATCTL_RX_IGNORE | instruction;
	
	/* transfer data */
	while( num != 0 ){
		while((LPC_SPI0->STAT& STAT_TXRDY) == 0);
		LPC_SPI0->TXDATCTL = TXDATCTL_FSIZE(8-1) | TXDATCTL_EOT | TXDATCTL_RX_IGNORE | *pbuff++;
		num--;
	}
	
	NRF24_Disable();
}
Exemplo n.º 5
0
void NRF24_InsRead(uint8_t instruction,uint8_t *pbuff,uint32_t num){
	uint16_t timeout ;
	NRF24_Enable();
	
	/* transfer instruction*/
	while((LPC_SPI0->STAT& STAT_TXRDY) == 0);
	LPC_SPI0->TXDATCTL = TXDATCTL_FSIZE(8-1) | TXDATCTL_EOT | TXDATCTL_RX_IGNORE | instruction;
	
	/* transfer data */
	while( num != 0 ){
		
		while((LPC_SPI0->STAT& STAT_TXRDY) == 0);
		LPC_SPI0->TXDATCTL = TXDATCTL_FSIZE(8-1) | TXDATCTL_EOT | 0xFF;
		
		timeout = 0xFFFF;
		while((LPC_SPI0->STAT& STAT_RXRDY) == 0 && timeout-- );
		*pbuff++ = LPC_SPI0->RXDAT;
		
		num--;
	}
	
	NRF24_Disable();
}
Exemplo n.º 6
0
/*****************************************************************************
** Function name:		SPI_Send
**
** Descriptions:		Send a block of data to the SPI port, the 
**						first parameter is slave select, the second is the buffer pointer, 
**						the 3rd parameter is the block length.
**
** parameters:			slave select, buffer pointer, and the block length
** Returned value:		None
** 
*****************************************************************************/
void SPI_Send( LPC_SPI_TypeDef *SPIx, SLAVE_t slave, uint8_t *tx, uint32_t Length )
{
  uint32_t i = 0;

  if ( Length == 1 ) {
#if SPI_INTERRUPT
		while(!txrdy);
		txrdy = 0;
		/* Set frame length to fixed 8 for now. */
		SPIx->TXDATCTL = TXDATCTL_SSELN(slave) | TXDATCTL_FSIZE(MASTER_FRAME_SIZE) 
			| TXDATCTL_RX_IGNORE | TXDATCTL_EOT | *tx;
		SPIx->INTENSET = STAT_TXRDY;
#else
		while ( (SPIx->STAT & STAT_TXRDY) == 0 );
		SPIx->TXDATCTL = TXDATCTL_SSELN(slave) | TXDATCTL_FSIZE(MASTER_FRAME_SIZE) 
			| TXDATCTL_RX_IGNORE | TXDATCTL_EOT | *tx;
#endif
		return;
  }

  while ( i < Length ) {
#if SPI_INTERRUPT
		while(!txrdy);
		txrdy = 0;
		/* Set frame length to fixed 8 for now. */
		if ( i == 0 ) {
			SPIx->TXDATCTL = TXDATCTL_SSELN(slave) | TXDATCTL_FSIZE(MASTER_FRAME_SIZE) 
				| TXDATCTL_RX_IGNORE | *tx++;
		}
		else if ( i == Length-1 ) {
			SPIx->TXDATCTL = TXDATCTL_SSELN(slave) | TXDATCTL_FSIZE(MASTER_FRAME_SIZE) 
				| TXDATCTL_RX_IGNORE | TXDATCTL_EOT | *tx++;
		}
		else {
			SPIx->TXDAT = *tx++;
		}
		SPIx->INTENSET = STAT_TXRDY;
#else
		/* Move only if TXRDY is ready */
		while ( (SPIx->STAT & STAT_TXRDY) == 0 );
		/* Set frame length to fixed 8 for now. */
		if ( i == 0 ) {
			SPIx->TXDATCTL = TXDATCTL_SSELN(slave) | TXDATCTL_FSIZE(MASTER_FRAME_SIZE) 
				| TXDATCTL_RX_IGNORE | *tx++;
		}
		else if ( i == Length-1 ) {
			SPIx->TXDATCTL = TXDATCTL_SSELN(slave) | TXDATCTL_FSIZE(MASTER_FRAME_SIZE) 
				| TXDATCTL_RX_IGNORE | TXDATCTL_EOT | *tx++;
		}
		else {
			SPIx->TXDAT = *tx++;
		}
#endif
		i++;
  }
  return; 
}
Exemplo n.º 7
0
/*****************************************************************************
** Function name:		SPI_Receive
** Descriptions:		the module will receive a block of data from 
**						the SPI, the 1st is the slave select, the 2nd parameter 
**						is the rx buffer pointer, the 3rd is the block length.
** parameters:			slave select, buffer pointer, and block length
** Returned value:		None
** 
*****************************************************************************/
void SPI_Receive( LPC_SPI_TypeDef *SPIx, SLAVE_t slave, uint8_t *rx, uint32_t Length )
{
  uint32_t i = 0;

  if ( Length == 1 ) {
#if SPI_INTERRUPT
		while(!txrdy);
		txrdy = 0;
		/* Set frame length to fixed 8 for now. */
		SPIx->TXDATCTL = TXDATCTL_SSELN(slave) | TXDATCTL_FSIZE(MASTER_FRAME_SIZE) | TXDATCTL_EOT | 0x55;
		SPIx->INTENSET = STAT_TXRDY;
		while(!rxrdy);
		rxrdy = 0;
		*rx = SPIx->RXDAT;
#if STALL_ENABLE
		SPIx->INTENSET = STAT_RXRDY | STAT_CLKSTALL;
#else
		SPIx->INTENSET = STAT_RXRDY;
#endif
#else
		while ( (SPIx->STAT & STAT_TXRDY) == 0 );
		SPIx->TXDATCTL = TXDATCTL_SSELN(slave) | TXDATCTL_FSIZE(MASTER_FRAME_SIZE) | TXDATCTL_EOT | 0x55;
		/* Read only if RX data is available. */
		while ( (SPIx->STAT & STAT_RXRDY) == 0 );
		*rx = SPIx->RXDAT;
#endif
		return;
  }

  while ( i < Length )
  {
#if SPI_INTERRUPT
		while(!txrdy);
		txrdy = 0;
		/* Set frame length to fixed 8 for now. */
		if ( i == 0 ) {
			SPIx->TXDATCTL = TXDATCTL_SSELN(slave) | TXDATCTL_FSIZE(MASTER_FRAME_SIZE) | 0x55;
		}
		else if ( i == Length-1 ) {
			SPIx->TXDATCTL = TXDATCTL_SSELN(slave) | TXDATCTL_FSIZE(MASTER_FRAME_SIZE) | TXDATCTL_EOT | 0x55;
		}
		else {
			SPIx->TXDAT = 0x55;
		}
		SPIx->INTENSET = STAT_TXRDY;
		while(!rxrdy);
		rxrdy = 0;
		*rx++ = SPIx->RXDAT;
#if STALL_ENABLE
		SPIx->INTENSET = STAT_RXRDY | STAT_CLKSTALL;
#else
		SPIx->INTENSET = STAT_RXRDY;
#endif
#else
		/* Move only if TXRDY is ready, write dummy 0x55 in order to read. */
		while ( (SPIx->STAT & STAT_TXRDY) == 0 );
		if ( i == 0 ) {
			SPIx->TXDATCTL = TXDATCTL_SSELN(slave) | TXDATCTL_FSIZE(MASTER_FRAME_SIZE) | 0x55;
    }
		else if ( i == Length-1 ) {
			SPIx->TXDATCTL = TXDATCTL_SSELN(slave) | TXDATCTL_FSIZE(MASTER_FRAME_SIZE) | TXDATCTL_EOT | 0x55;
		}
		else {
			SPIx->TXDAT = 0x55;
		}
		/* Read only if RX data is available. */
		while ( (SPIx->STAT & STAT_RXRDY) == 0 );
		*rx++ = SPIx->RXDAT;
#endif
		i++;
  }
  return; 
}
Exemplo n.º 8
0
/*****************************************************************************
** Function name:		SPI_SendRcv
**
** Descriptions:		Send a block of data to the SPI port, the 
**									first parameter is the buffer pointer, the 2nd 
**									parameter is the block length.
**
** parameters:			buffer pointer, and the block length
** Returned value:		None
** 
*****************************************************************************/
void SPI_SendRcv( LPC_SPI_TypeDef *SPIx, SLAVE_t slave, uint8_t *tx, uint8_t *rx, uint32_t Length )
{
  uint32_t i = 0;

  if ( Length == 1 ) {
#if SPI_INTERRUPT
		while(!txrdy);
		txrdy = 0;
		/* Set frame length to fixed 8 for now. */
		SPIx->TXDATCTL = TXDATCTL_SSELN(slave) | TXDATCTL_FSIZE(MASTER_FRAME_SIZE) | TXDATCTL_EOT | *tx;
		SPIx->INTENSET = STAT_TXRDY;
		while(!rxrdy);
		rxrdy = 0;
		*rx = SPIx->RXDAT;
#if STALL_ENABLE
		SPIx->INTENSET = STAT_RXRDY | STAT_CLKSTALL;
#else
		SPIx->INTENSET = STAT_RXRDY;
#endif
#else
		while ( (SPIx->STAT & STAT_TXRDY) == 0 );
		/* Set frame length to fixed 8 for now. */
		SPIx->TXDATCTL = TXDATCTL_SSELN(slave) | TXDATCTL_FSIZE(MASTER_FRAME_SIZE) | TXDATCTL_EOT | *tx;
		while ( (SPIx->STAT & STAT_RXRDY) == 0 );
		*rx = SPIx->RXDAT;
#endif
		return;
  }

  while ( i < Length ) {
	/* Move only if TXRDY is ready */
#if SPI_INTERRUPT
		while(!txrdy);
		txrdy = 0;
		/* Set frame length to fixed 8 for now. */
		if ( i == 0 ) {
			SPIx->TXDATCTL = TXDATCTL_SSELN(slave) | TXDATCTL_FSIZE(MASTER_FRAME_SIZE) | *tx++;
		}
		else if ( i == Length-1 ) {
			SPIx->TXDATCTL = TXDATCTL_SSELN(slave) | TXDATCTL_FSIZE(MASTER_FRAME_SIZE) | TXDATCTL_EOT | *tx++;
		}
		else {
			SPIx->TXDAT = *tx++;
		}
		SPIx->INTENSET = STAT_TXRDY;
		while(!rxrdy);
		rxrdy = 0;
		*rx++ = SPIx->RXDAT;
#if STALL_ENABLE
		SPIx->INTENSET = STAT_RXRDY | STAT_CLKSTALL;
#else
		SPIx->INTENSET = STAT_RXRDY;
#endif
#else
		while ( (SPIx->STAT & STAT_TXRDY) == 0 );
		/* Set frame length to fixed 8 for now. */
		if ( i == 0 ) {
			SPIx->TXDATCTL = TXDATCTL_SSELN(slave) | TXDATCTL_FSIZE(MASTER_FRAME_SIZE) | *tx++;
		}
		else if ( i == Length-1 ) {
			SPIx->TXDATCTL = TXDATCTL_SSELN(slave) | TXDATCTL_FSIZE(MASTER_FRAME_SIZE) | TXDATCTL_EOT | *tx++;
		}
		else {
			SPIx->TXDAT = *tx++;
		}
		while ( (SPIx->STAT & STAT_RXRDY) == 0 );
		*rx++ = SPIx->RXDAT;
#endif
		i++;
  }
  return; 
}