Go to Post If the pattern holds, it's a bizarro year. - GeeTwo [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 17-01-2015, 12:50
pfish3138 pfish3138 is offline
Registered User
FRC #3138 (Innovators Robotics)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Dayton
Posts: 8
pfish3138 is an unknown quantity at this point
RoboRIO SPI Configuration

Previously WPILib provided support for configuring the bits per word for SPI. Does anyone know how to do that for the RoboRIO built-in SPI?
Reply With Quote
  #2   Spotlight this post!  
Unread 07-02-2015, 02:34
Team118Joseph's Avatar
Team118Joseph Team118Joseph is offline
The guy that did the lighting
AKA: Joseph Foster
FRC #0118 (Robonauts)
Team Role: Alumni
 
Join Date: Jan 2014
Rookie Year: 2013
Location: League City
Posts: 61
Team118Joseph will become famous soon enoughTeam118Joseph will become famous soon enough
Re: RoboRIO SPI Configuration

I'm having the same problem. The SPI code that worked on our CRios wont work on the RoboRio because of this.
__________________
FRC Countdown Website: http://frccountdown.hosthorde.net/
FRC Countdowns App: https://play.google.com/store/apps/d...h.frccountdown
Reply With Quote
  #3   Spotlight this post!  
Unread 08-02-2015, 17:21
Team118Joseph's Avatar
Team118Joseph Team118Joseph is offline
The guy that did the lighting
AKA: Joseph Foster
FRC #0118 (Robonauts)
Team Role: Alumni
 
Join Date: Jan 2014
Rookie Year: 2013
Location: League City
Posts: 61
Team118Joseph will become famous soon enoughTeam118Joseph will become famous soon enough
Re: RoboRIO SPI Configuration

I found a solution. You can use the Linux spidev. It is the standard SPI interface for Linux microcomputers. With it you can set all the low level SPI settings including the bits per word. Documentation can be found here https://www.kernel.org/doc/Documentation/spi/spidev.

This is the code I use to enable the spi port:
Code:
/******************************************************************************
 *
 * Initializes the spi
 *
 ******************************************************************************/
void Lights::initSPI()
{
	//SPI setup
	int ret = 0;
	fd = 0;
	fd = open(device, O_RDWR);
	if (fd <0)
	{
		output->printError("can't open device");
	}

	/*************************************************************************************************
	 * spi mode
	 */
	//ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
	//if (ret ==-1)
	//{
	//	output->printError("can't set spi mode");
	//}

	ret = ioctl(fd, SPI_IOC_RD_LSB_FIRST, &msb);
	if (ret ==-1)
	{
		output->printError("can't set spi mode");
	}
	printf("MSB mode: %d\n",msb);

	/*
	 * bits per word
	 */
	ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
	if (ret ==-1)
	{
		output->printError("can't set bits per word");
	}

	/*
	 * max speed hz
	 */
	ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
	if (ret ==-1)
	{
		output->printError("can't set max speed hz");
	}

	tr.tx_buf = (unsigned long) master_array;
	tr.rx_buf = (unsigned long) NULL;
	tr.len = total_size *3;
	tr.delay_usecs = delay;
	tr.speed_hz = speed;
	tr.bits_per_word = bits;

	printf("spi mode: %d\n", mode);
	printf("bits per word: %d\n", bits);
	printf("max speed: %d Hz (%d KHz)\n", speed, speed /1000);
}
device is a const char* set to one of the following:
Code:
const char *device = "/dev/spidev0.X"; //for the main SPI port with chip select X
const char *device = "/dev/spidev1.0"; //for the SPI port on the Custom Electronics Board
and the rest of the settings in the header are:
Code:
//SPI interface
int fd;
struct spi_ioc_transfer tr;
const char *device = "/dev/spidev0.0";
const uint8_t mode = SPI_MODE_0;
const uint8_t msb = 0;
const uint8_t bits = 8;
const uint32_t speed = 800000;
Then to send/receive data I use the following:
Code:
/**********************************************************************
 *
 * Sends the frame over SPI
 * 
 **********************************************************************/
void Lights::transmitFrame()
{
	finalizeFrame();
	if ((ioctl(fd, SPI_IOC_MESSAGE(1), &tr)) ==-1)
	{
		output->printError("transmit failed");
	}

	for (uint16_t i = 0; i <segment_cnt; i++)
	{
		segment_bank[i]->renderFrame();
	}

}
I plan on making a class that will do all of the hard work and posting it on Delphi.
__________________
FRC Countdown Website: http://frccountdown.hosthorde.net/
FRC Countdowns App: https://play.google.com/store/apps/d...h.frccountdown
Reply With Quote
  #4   Spotlight this post!  
Unread 08-02-2015, 17:28
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 989
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: RoboRIO SPI Configuration

Quote:
Originally Posted by Team118Joseph View Post
can set all the low level SPI settings including the bits per word.
Have you confirmed that changing this setting actually changes the port behavior? If they removed it from the API I assume it was for a reason.
Reply With Quote
  #5   Spotlight this post!  
Unread 08-02-2015, 23:32
Team118Joseph's Avatar
Team118Joseph Team118Joseph is offline
The guy that did the lighting
AKA: Joseph Foster
FRC #0118 (Robonauts)
Team Role: Alumni
 
Join Date: Jan 2014
Rookie Year: 2013
Location: League City
Posts: 61
Team118Joseph will become famous soon enoughTeam118Joseph will become famous soon enough
Re: RoboRIO SPI Configuration

Quote:
Originally Posted by RufflesRidge View Post
Have you confirmed that changing this setting actually changes the port behavior? If they removed it from the API I assume it was for a reason.
Yes, we have confirmed it. We ran our LPD-8806 lights off of them and they worked perfectly. The LPD-8806 lights are 8 bits per word and the WPILib API seems to only provides 7 bits per word. With the spidev, we were able to change the output to 8 bits per word.

The old SPI class from the WPI library wasn't actually SPI. On the CRio it would bit bang the Digital IO ports to act like SPI. The problem with that is the software had to take resources away from other tasks to emulate SPI. The RoboRio has dedicated hardware for SPI so it doesn't need to take away valuable resources from the rest of the robot. I don't know why they didn't put in the bits per word setting into the new SPI class. The only reason I can think of is that a lot of IC's use 7 bits per word. But that doesn't explain why they wouldn't give us the option to change it.
__________________
FRC Countdown Website: http://frccountdown.hosthorde.net/
FRC Countdowns App: https://play.google.com/store/apps/d...h.frccountdown

Last edited by Team118Joseph : 08-02-2015 at 23:37. Reason: Added details and explanation
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 14:04.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi