EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

SPI bit-banging examples?

Started by Richard Cooke June 27, 2007
Hi Folks,

I need to use the MSP430F2111 due to cost issues (and at least 16 I/0)
but I also need to interface to a Nordic RF chip via SPI. This
particular flavor of MSP doesn't have a hardware SPI port so I'm stuck
with bit-banging.

Can some kind soul point me to an example or framework that shows this
bit-banging of a SPI interface.

Thanks,

Richard Cooke

Beginning Microcontrollers with the MSP430

There's nothing to bit-banging. Just look at the data sheet for the
chip you're talking to and flip the bits! There aren't too many
canned examples of this because when people are bit-banging, it's
because they have special needs.

You could:
Setup a timer ISR at 2x your bit rate.
For writing:
Every odd-numbered ISR take your data bit, mask out the LSBit, put it
on our data port. Toggle your clock port bit.
Ever even-numbered ISR, toggle your clock bit.
For reading:
Do the same as writing, but shift IN data bits.

You can do it!

Stuart

--- In m..., "Richard Cooke" wrote:
>
> Hi Folks,
>
> I need to use the MSP430F2111 due to cost issues (and at least 16 I/0)
> but I also need to interface to a Nordic RF chip via SPI. This
> particular flavor of MSP doesn't have a hardware SPI port so I'm stuck
> with bit-banging.
>
> Can some kind soul point me to an example or framework that shows this
> bit-banging of a SPI interface.
>
> Thanks,
>
> Richard Cooke
>
I agree with Rubin. You need four wires: Select, Data Out, Data In and Clock.
Select the device, raise or lower Data Out, raise and then lower the Clock,
Test Data In for a bit.

As Rubin points out the actual routine will be defined by the data sheet of
the device you are driving.

Crane

Richard Cooke-2 wrote:
>
> Hi Folks,
>
> I need to use the MSP430F2111 due to cost issues (and at least 16 I/0)
> but I also need to interface to a Nordic RF chip via SPI. This
> particular flavor of MSP doesn't have a hardware SPI port so I'm stuck
> with bit-banging.
>
> Can some kind soul point me to an example or framework that shows this
> bit-banging of a SPI interface.
>
> Thanks,
>
> Richard Cooke
>

--
When i made code to bitbang an spi device (AT25040N), i started from this TI sample code.
I hope this helps..

regards,
mago

#include
#define CS 0x01 // P2.0 - Chip Select
#define CLK 0x02 // P2.1 - Clock
#define DO 0x08 // P2.3 - Data Out
void main (void)
{
unsigned char ADCData;
unsigned char Counter;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P2OUT = CS; // /CS set, - P2.x reset
P2DIR |= CLK + CS; // /CS and CLK outputs
P1DIR |= 0x01; // Set P1.0 to output direction
for (;;) // Infinite loop
{
P2OUT &= ~CS; // /CS reset, enable ADC
for (Counter = 8; Counter > 0;)
{
ADCData = ADCData << 1;
if ((P2IN & DO) == DO)
{
ADCData |= 0x01;
}
Counter --;
P2OUT |= CLK; // Clock high
P2OUT &= ~CLK; // Clock low
}
P2OUT |= CS; // /CS set, disable ADC
if (ADCData < 0x7F)
{
P1OUT &= ~0x01; // Clear P1.0 LED off
}
else
{
P1OUT |= 0x01; // Set P1.0 LED on
}
}
}

Stuart_Rubin wrote:
There's nothing to bit-banging. Just look at the data sheet for the
chip you're talking to and flip the bits! There aren't too many
canned examples of this because when people are bit-banging, it's
because they have special needs.

You could:
Setup a timer ISR at 2x your bit rate.
For writing:
Every odd-numbered ISR take your data bit, mask out the LSBit, put it
on our data port. Toggle your clock port bit.
Ever even-numbered ISR, toggle your clock bit.
For reading:
Do the same as writing, but shift IN data bits.

You can do it!

Stuart

--- In m..., "Richard Cooke" wrote:
>
> Hi Folks,
>
> I need to use the MSP430F2111 due to cost issues (and at least 16 I/0)
> but I also need to interface to a Nordic RF chip via SPI. This
> particular flavor of MSP doesn't have a hardware SPI port so I'm stuck
> with bit-banging.
>
> Can some kind soul point me to an example or framework that shows this
> bit-banging of a SPI interface.
>
> Thanks,
>
> Richard Cooke
>

---------------------------------
The fish are biting.
Get more visitors on your site using Yahoo! Search Marketing.
It's also a good idea to leave the clock high (in this example SPI mode) before deasserting
CS. Some SPI devices will require this. (add marked by ****)

for (Counter = 8; Counter > 0;)
{
ADCData = ADCData << 1;
if (P2IN & DO)
{
ADCData |= 0x01;
}
Counter --;
P2OUT |= CLK; // Clock high
P2OUT &= ~CLK; // Clock low
}
P2OUT |= (CLK + CS); // Clock high BEFORE strobing ***
// /CS set, disable ADC

I do realise this was simple example code of course.

Best Regards,
Kris

-----Original Message-----
From: m... [mailto:m...] On Behalf Of mago Umandam
Sent: Friday, 29 June 2007 10:10 AM
To: m...
Subject: Re: [msp430] Re: SPI bit-banging examples?

When i made code to bitbang an spi device (AT25040N), i started from this TI sample code.
I hope this helps..

regards,
mago

#include
#define CS 0x01 // P2.0 - Chip Select
#define CLK 0x02 // P2.1 - Clock
#define DO 0x08 // P2.3 - Data Out
void main (void)
{
unsigned char ADCData;
unsigned char Counter;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P2OUT = CS; // /CS set, - P2.x reset
P2DIR |= CLK + CS; // /CS and CLK outputs
P1DIR |= 0x01; // Set P1.0 to output direction
for (;;) // Infinite loop
{
P2OUT &= ~CS; // /CS reset, enable ADC
for (Counter = 8; Counter > 0;)
{
ADCData = ADCData << 1;
if ((P2IN & DO) == DO)
{
ADCData |= 0x01;
}
Counter --;
P2OUT |= CLK; // Clock high
P2OUT &= ~CLK; // Clock low
}
P2OUT |= CS; // /CS set, disable ADC
if (ADCData < 0x7F)
{
P1OUT &= ~0x01; // Clear P1.0 LED off
}
else
{
P1OUT |= 0x01; // Set P1.0 LED on
}
}
}
Hi everybody !

I don't really know how does work a bit-banging... Anyway, I am looking for advice or code sample to help me to program a software to use SPI to write/read data into/from an external flash (AT45DB642D). I'm already using the two USART ports of the MSP430F1611... Consequently I have to program it entirely in C or asm using for example P4.0,P4.1,P4.2, P4.3 pins as CS, SIMO, SOMI, CLK...

Anybody can help me ?

Thanks
Hi everybody !

I don't really know how does work a bit-banging... Anyway, I am looking for advice or code sample to help me to program a software to use SPI to write/read data into/from an external flash (AT45DB642D). I'm already using the two USART ports of the MSP430F1611... Consequently I have to program it entirely in C or asm using for example P4.0,P4.1,P4.2, P4.3 pins as CS, SIMO, SOMI, CLK...

Anybody can help me ?

Thanks
http://webspace.webring.com/people/jl/leon_heller/
----- Original Message -----
From:
To:
Sent: Wednesday, August 08, 2007 9:58 AM
Subject: [msp430] Re: SPI bit-banging examples?
> Hi everybody !
>
> I don't really know how does work a bit-banging... Anyway, I am looking
> for advice or code sample to help me to program a software to use SPI to
> write/read data into/from an external flash (AT45DB642D). I'm already
> using the two USART ports of the MSP430F1611... Consequently I have to
> program it entirely in C or asm using for example P4.0,P4.1,P4.2, P4.3
> pins as CS, SIMO, SOMI, CLK...
You simply set the data pin high or low, and toggle the clock. All the
details you need will be in the flash chip data sheet. Look at the TI FET
examples for some typical code, like the software SPI for the TLC549.

Leon
--
Leon Heller
Amateur radio call-sign G1HSM
Yaesu FT-817ND and FT-857D transceivers
Suzuki SV1000S motorcycle
l...@btinternet.com
Hello,

you can find the spi bit-banging example in TI application note "MSP430
Interface to CC1100/2500 Code Library". C Code is also provided with this
application note in which SPI bit.banging is also implemented.

Mukry

Bobish wrote:
>
> Hi everybody !
>
> I don't really know how does work a bit-banging... Anyway, I am looking
> for advice or code sample to help me to program a software to use SPI to
> write/read data into/from an external flash (AT45DB642D). I'm already
> using the two USART ports of the MSP430F1611... Consequently I have to
> program it entirely in C or asm using for example P4.0,P4.1,P4.2, P4.3
> pins as CS, SIMO, SOMI, CLK...
>
> Anybody can help me ?
>
> Thanks

--
Thanks Mukry ! I think I will find everything I want in the Applicaton Note N49 by selecting SPI BitBang config !

Have a nice day !

Bobish
To: m...From: p...@yahoo.comDate: Sun, 12 Aug 2007 02:16:22 -0700Subject: Re: [msp430] SPI bit-banging examples?

Hello,you can find the spi bit-banging example in TI application note "MSP430Interface to CC1100/2500 Code Library". C Code is also provided with thisapplication note in which SPI bit.banging is also implemented.Mukry Bobish wrote:> > Hi everybody !> > I don't really know how does work a bit-banging... Anyway, I am looking> for advice or code sample to help me to program a software to use SPI to> write/read data into/from an external flash (AT45DB642D). I'm already> using the two USART ports of the MSP430F1611... Consequently I have to> program it entirely in C or asm using for example P4.0,P4.1,P4.2, P4.3> pins as CS, SIMO, SOMI, CLK...> > Anybody can help me ?> > Thanks > > --
_________________________________________________________________
Besoin d'un e-mail ? Crz gratuitement un compte Windows Live Hotmail et gagnez du temps avec l'interface la Outlook !
http://www.windowslive.fr/hotmail/default.asp

The 2024 Embedded Online Conference