Serial interface

New to XMOS and XCore? Get started here.
Ganux
Active Member
Posts: 35
Joined: Tue Mar 08, 2011 12:58 pm

Serial interface

Postby Ganux » Sun Jun 05, 2011 6:36 pm

Hello,

I need to write a serial interface for a MAX6974.
Now, I can't just serialize (out port p_led_data:8 = PORT_LED_OUT_DATA;)
because my data has lengths from 6 to 12 bit.

I came up with 2 ways that might possibly work.
first one: changing the serialization value:

int main(ports){
out port p_led_data:6 = PORT_LED_OUT_DATA;
* some code *
out port p_led_data:8 = PORT_LED_OUT_DATA;
* some code *
out port p_led_data:12 = PORT_LED_OUT_DATA;
* some code *
}

second: not serializing, and sending it with a loop:
out port p_led_data = PORT_LED_OUT_DATA;
int main(ports){
int sync = 232;
for( int i = 0; i < 7; i++){
p_led_data <: sync << (7-i); //most significant bit first like this??
}
}

I hope you guys can help me out with this one! ;-)

Greetings,

Ganux_
User avatar
Andy
Respected Member
Posts: 279
Joined: Fri Dec 11, 2009 1:34 pm

Postby Andy » Sun Jun 05, 2011 8:03 pm

The second option looks a lot more sensible. If you really need the extra cycles gained from using a buffered port, I believe you can also achieve partial output using the partout() library function.

It's in xs1.h:

Code: Select all

 * Performs an output of the specified width on a buffered port.
 * The width must be less than the transfer width of the port, greater than
 * zero and a multiple of the port width, otherwise an exception is raised.
 * The \a n least significant bits of \a val are output.
 * \param p The buffered port to output on.
 * \param n The number of bits to output.
 * \param val The value to output.
void partout(/* buffered */ void port p, unsigned n, unsigned val);

Who is online

Users browsing this forum: No registered users and 5 guests