OK this may be simple but is it possible to use a 4bit port and set some INPUT and some OUTPUT?
Can someone post a example?
Multibit ports
-
- XCore Addict
- Posts: 135
- Joined: Mon Dec 14, 2009 3:02 pm
-
- XCore Expert
- Posts: 844
- Joined: Sun Jul 11, 2010 1:31 am
Nope.
The exception is when you have two ports that use the same
pins: if you enable both ports, then the smaller port gets
the overlapping pins. So in that case you can have both
directions on the pins of one port. But the 4-bit ports do
not overlap with any 1-bit ports.
The exception is when you have two ports that use the same
pins: if you enable both ports, then the smaller port gets
the overlapping pins. So in that case you can have both
directions on the pins of one port. But the 4-bit ports do
not overlap with any 1-bit ports.
-
- XCore Addict
- Posts: 135
- Joined: Mon Dec 14, 2009 3:02 pm
wow, seems like a bad design decision :(
Oh well... off to make another PCB and scrap this one... thank goodness i made it here at home :)
Thanks :)
Oh well... off to make another PCB and scrap this one... thank goodness i made it here at home :)
Thanks :)
-
- XCore Addict
- Posts: 135
- Joined: Mon Dec 14, 2009 3:02 pm
Why is this like over complicated lol.
-
- XCore Expert
- Posts: 844
- Joined: Sun Jul 11, 2010 1:31 am
What is complicated about it? In a 4-bit port, all 4 bits are
changed or read at the same time. It is not like the ports
on legacy microcomputer-age devices, that have all bits
independent for most things. Features like serialisation do
not work well together with that.
Why do you need to scrap your design?
changed or read at the same time. It is not like the ports
on legacy microcomputer-age devices, that have all bits
independent for most things. Features like serialisation do
not work well together with that.
Why do you need to scrap your design?
-
- XCore Addict
- Posts: 135
- Joined: Mon Dec 14, 2009 3:02 pm
I had a spi (4bit) on a 4bit port which wouldnt allow me to read the MISO. I need that on a single port. or another set where i can make all input.
The over complicated stuff comes from my history with PIC, ARM, AVR , FPGA where you can set each individual bit of a port to input or output so for instance in PIC
TRISC = 0x04; // pin 3 of portC is input the rest output
Then i can read a single bit if needed:
readVal = PORTCbits.RC3; // Read pin 3 of portC
Or i can write entire ports
PORTC = 0x01; or LATC = 0x01
or bits
PORTCbits.RC1 = 1 ; or LATCbits.LATC1 = 1;
See how simple that is compared to XMOS :) ?
The over complicated stuff comes from my history with PIC, ARM, AVR , FPGA where you can set each individual bit of a port to input or output so for instance in PIC
TRISC = 0x04; // pin 3 of portC is input the rest output
Then i can read a single bit if needed:
readVal = PORTCbits.RC3; // Read pin 3 of portC
Or i can write entire ports
PORTC = 0x01; or LATC = 0x01
or bits
PORTCbits.RC1 = 1 ; or LATCbits.LATC1 = 1;
See how simple that is compared to XMOS :) ?
-
- XCore Expert
- Posts: 844
- Joined: Sun Jul 11, 2010 1:31 am
"Ports" on those devices are just a collection of pins that
you use largely independently; where that independence
breaks down, the problems start. XS1 ports are more like
busses: you control all pins at the same time. This is much
nicer and simpler IMO, certainly more powerful (esp. for
fast signals).
It would be nice to be able to tristate individual pins of
(say) port 32A, so that you can both input and output slow
bulk signals on that same port, I agree. But that's about
everything that is nicer about those traditional I/O blocks :-)
you use largely independently; where that independence
breaks down, the problems start. XS1 ports are more like
busses: you control all pins at the same time. This is much
nicer and simpler IMO, certainly more powerful (esp. for
fast signals).
It would be nice to be able to tristate individual pins of
(say) port 32A, so that you can both input and output slow
bulk signals on that same port, I agree. But that's about
everything that is nicer about those traditional I/O blocks :-)
-
- XCore Addict
- Posts: 135
- Joined: Mon Dec 14, 2009 3:02 pm
Im just toying with this but what are your thoughts.... This does not use the PEEK function at all... but max speed seems to hit 1.4MHz ... any thoughts?
Code: Select all
unsigned char spi2_2_transfer (unsigned char data)
{
char x = 0;
char inbit;
unsigned char returnData = 0;
unsigned char SPIBUS = 0;
for(x=0;x<8;x++)
{
if(data & 0x80)
SPIBUS |= MOSI;
else
SPIBUS &= ~MOSI;
data <<= 1;
SPI2 <: SPIBUS;
SPIBUS |= CLK;
SPI2 <: SPIBUS;
MISO :> inbit;
if(inbit)
returnData |= 1;
returnData <<= 1;
SPIBUS &= ~CLK;
SPI2 <: SPIBUS;
}
return returnData;
}
You do not have the required permissions to view the files attached to this post.
-
- XCore Expert
- Posts: 844
- Joined: Sun Jul 11, 2010 1:31 am
The two statements assigning returnData should be swapped.
You are outputting thrice per loop, you only need twice; you
can lose the last one, do it once more after the loop.
You are using character types where it's not needed. Using
"int" or "unsigned int" is more efficient.
Look at the generated code to see if efficient code is generated.
Do you have all optimisation disabled, perhaps?
You are outputting thrice per loop, you only need twice; you
can lose the last one, do it once more after the loop.
You are using character types where it's not needed. Using
"int" or "unsigned int" is more efficient.
Look at the generated code to see if efficient code is generated.
Do you have all optimisation disabled, perhaps?
-
- XCore Addict
- Posts: 135
- Joined: Mon Dec 14, 2009 3:02 pm
Thanks i tried removing the last output but get a settings mismatch in the analyzer meaning its no longer MODE 0... which is bad... so i left it in...
I changed all to INT...I swapped the data in statements... i now get 1.778MHz as the clock... im about to check optimizations
I changed all to INT...I swapped the data in statements... i now get 1.778MHz as the clock... im about to check optimizations
Code: Select all
unsigned char spi2_2_transfer (unsigned char data)
{
int x = 0;
int inbit;
int returnData = 0;
int SPIBUS = 0;
for(x=0;x<8;x++)
{
if(data & 0x80)
SPIBUS |= MOSI;
else
SPIBUS &= ~MOSI;
data <<= 1;
SPI2 <: SPIBUS;
SPIBUS |= CLK;
SPI2 <: SPIBUS;
MISO :> inbit;
returnData <<= 1;
if(inbit)
returnData |= 1;
SPIBUS &= ~CLK;
SPI2 <: SPIBUS;
}
return (unsigned char)returnData;
}