EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

bx24 - max1270

Started by Paul J. Smith July 23, 2005
Hello,

Has anyone managed to interface one of these to the BX24 and would like
to share the code?

I have found very simple sample code for the stamp

sleeptime con 100
bytea var byte
byteb var byte
midicommand con $A0
midioutpin con 7
midirate con 60
clockpin con 11
cspin con 10
outputpin con 9
inputpin con 8
msb con 1
behindclock con 2
controlbyte con %10000001

top:
gosub ReadSensorData
gosub SendSensorData
pause sleeptime
goto top

ReadSensorData:
bytea = 0
byteb = 0
shiftout outputpin, clockpin, msb, [controlbyte \ 8]
shiftout outputpin, clockpin, msb, [0 \ 4]
shiftin inputpin, clockpin, behindclock, [bytea \ 7]
shiftin inputpin, clockpin, behindclock, [byteb \ 5]
return

SendSensorData:
serout midioutpin, midirate, [midicommand, bytea, byteb]
return But I'm having problems converting this. The processor waits 4 cycles
after you send the result before it provides it. I don't know how to
make the mx24 wait that 4 cycles, which I'm guessing is what the
shiftout outputpin, clockpin, msb, [0 \ 4] is for in the above.

SPI seems quite difficult to me! Perhaps any other examples for similar
chips might help if someone can point me in the right direction?

Thanks



--- In basicx@basi..., "Paul J. Smith" <pjsmith@m...> wrote:
> [...] I don't know how to make the mx24 wait that 4 cycles,
> which I'm guessing is what the shiftout outputpin, clockpin, msb,
> [0 \ 4] is for in the above.

The control byte that is specified (10000001) indicates
that "external clock" mode is being used. That means that the clock
output from the BX-24 is used by the MAX1270 for its internal
timing. All that you need to do is shift out four bits - any four
bits will do because the MAX1270 ignores them.

Call ShiftOut(dataPin, clkPin, 4, 0)

One other aspect of this that might cause a problem is that the
PBasic code specifies that when shifting data in the data line
should be sampled after the clock edge. The BX-24 doesn't support
this mode - it always samples the data line just before the clock
edge. That doesn't necessarily mean that you can't make it work.
Study the timing diagrams in the datasheet and draw yourself some
diagrams of what you expect the timing from the BX-24 to look like.

Don


To followup on Don's comments, one of my greatest 'frustration' with
the BX-24 is the lack of ability to control the Clock Edge... This
has made it a real 'pain' to port Stamp code. That and the limited 8-
Bit transfer. I often have to resort to 'Bit-banging' an SPI-style
interface. NetMedia really needs to take an example from the Stamp's
PulseIn/Out routines...

- Tom

--- In basicx@basi..., "Don Kinzer" <dkinzer@e...> wrote:
> --- In basicx@basi..., "Paul J. Smith" <pjsmith@m...> wrote:
> > [...] I don't know how to make the mx24 wait that 4 cycles,
> > which I'm guessing is what the shiftout outputpin, clockpin, msb,
> > [0 \ 4] is for in the above.
>
> The control byte that is specified (10000001) indicates
> that "external clock" mode is being used. That means that the
clock
> output from the BX-24 is used by the MAX1270 for its internal
> timing. All that you need to do is shift out four bits - any four
> bits will do because the MAX1270 ignores them.
>
> Call ShiftOut(dataPin, clkPin, 4, 0)
>
> One other aspect of this that might cause a problem is that the
> PBasic code specifies that when shifting data in the data line
> should be sampled after the clock edge. The BX-24 doesn't support
> this mode - it always samples the data line just before the clock
> edge. That doesn't necessarily mean that you can't make it work.
> Study the timing diagrams in the datasheet and draw yourself some
> diagrams of what you expect the timing from the BX-24 to look like.
>
> Don


--- In basicx@basi..., "tombhandley" <gr13tbs@c...> wrote:
> NetMedia really needs to take an example from the Stamp's
> PulseIn/Out routines...

I assume that you meant ShiftIn/Out routines. Except for timing the
PulseIn/Out routines are almost identical to PULSIN/PULSOUT. One
minor difference is that PULSOUT infers the desired pulse polarity
from the current output state.

Don


Thanks very much for this.

Sorry, but I'm bit of a beginner programming microprocessors like the
bx24. I'm using the SPI commands. Can you use the ShiftOut in
combination with the SPI commands/bus? It looks like a different method
of communication to me?

I have the sclk, miso, and mosi pins from the bx24 connected to the
1270.

The data sheet for the 1270 does show the data starts on the falling
edge of the sclk. It starts when it receives the control byte, starts
acquisition on the 6th bit. Conversion takes 6 sclk from the 6th bit of
the control byte, then you read the result on the next 12 bits. There
is a sstrb after the conversion time that takes 2 sclk cycles.

The code I have so far is

Const CSPin as Byte = 13

Sub Max1270()

Dim SPIChannel as Byte
Dim SPISetupByte as byte
Dim V as integer

SPISetUpByte = 1
SPIChannel = 1
Call OpenSPI(SPIChannel, SPISetUpByte, CSPin)

Dim PutData(1 to 2) as Byte, GetData(1 to 2) as Byte

' Put control byte
PutData(1) = bx10000001
Call SPICmd(SPIChannel, 1, PutData(1), 0, GetData(1))
' wait 4 clock cycles
Call ShiftOut(17, 3, 4, 0)
' receive 16 bit result
Call SPICmd(SPIChannel, 0, PutData(1), 1, GetData(1))
Call SPICmd(SPIChannel, 0, PutData(1), 1, GetData(2))

' Put the high and low bytes together. Result is in lower 12-bits.
v = CInt(GetData(1)) * 16 + CInt(GetData(2))\16

debug.print cstr(v)

End sub
-----Original Message-----
From: basicx@basi... [mailto:basicx@basi...] On Behalf
Of Don Kinzer
Sent: 24 July 2005 00:47
To: basicx@basi...
Subject: [BasicX] Re: bx24 - max1270

--- In basicx@basi..., "Paul J. Smith" <pjsmith@m...> wrote:
> [...] I don't know how to make the mx24 wait that 4 cycles,
> which I'm guessing is what the shiftout outputpin, clockpin, msb,
> [0 \ 4] is for in the above.

The control byte that is specified (10000001) indicates
that "external clock" mode is being used. That means that the clock
output from the BX-24 is used by the MAX1270 for its internal
timing. All that you need to do is shift out four bits - any four
bits will do because the MAX1270 ignores them.

Call ShiftOut(dataPin, clkPin, 4, 0)

One other aspect of this that might cause a problem is that the
PBasic code specifies that when shifting data in the data line
should be sampled after the clock edge. The BX-24 doesn't support
this mode - it always samples the data line just before the clock
edge. That doesn't necessarily mean that you can't make it work.
Study the timing diagrams in the datasheet and draw yourself some
diagrams of what you expect the timing from the BX-24 to look like.

Don

Yahoo! Groups Links


--- In basicx@basi..., "Paul J. Smith" <pjsmith@m...> wrote:
> Can you use the ShiftOut in combination with the SPI commands/bus?

Probably not. Since the BX-24 uses the SPI bus to read instructions
from the external EEPROM, attempting to use BasicX instructions to
manipulate the SPI I/O lines would probably not work. Also, I don't
know how you would get the SPI interface to send the 1270 the four
clock cycles that it needs between the command byte and the outputting
of the data.

If you want to use an SPI interface, check out Tom's example code of
big-banged SPI (and other protocols) on the page at:
http://home.comcast.net/~tomhandley/bx-24/bx-24.html

Don



Thanks. This example was exactly what I needed. This code seems much
more flexible than the built in instructions and allows me to set rising
or falling edge for the clock for data transfer :)

I'm getting some results now, so I think I am almost there.

-----Original Message-----
From: basicx@basi... [mailto:basicx@basi...] On Behalf
Of Don Kinzer
Sent: 25 July 2005 16:11
To: basicx@basi...
Subject: [BasicX] Re: bx24 - max1270

--- In basicx@basi..., "Paul J. Smith" <pjsmith@m...> wrote:
> Can you use the ShiftOut in combination with the SPI commands/bus?

Probably not. Since the BX-24 uses the SPI bus to read instructions
from the external EEPROM, attempting to use BasicX instructions to
manipulate the SPI I/O lines would probably not work. Also, I don't
know how you would get the SPI interface to send the 1270 the four
clock cycles that it needs between the command byte and the outputting
of the data.

If you want to use an SPI interface, check out Tom's example code of
big-banged SPI (and other protocols) on the page at:
http://home.comcast.net/~tomhandley/bx-24/bx-24.html

Don
Yahoo! Groups Links


Don, yes, I meant ShiftIn/Out. The Stamp allows Clock-Edge and number
of Bits up to 16 via the "/[bits]" parameter.

- Tom

--- In basicx@basi..., "Don Kinzer" <dkinzer@e...> wrote:
> --- In basicx@basi..., "tombhandley" <gr13tbs@c...> wrote:
> > NetMedia really needs to take an example from the Stamp's
> > PulseIn/Out routines...
>
> I assume that you meant ShiftIn/Out routines. Except for timing the
> PulseIn/Out routines are almost identical to PULSIN/PULSOUT. One
> minor difference is that PULSOUT infers the desired pulse polarity
> from the current output state.
>
> Don


Paul, this is a typical example of why a lot of hardware SPI
interfaces do not work... I've resorted to 'Bit-banging' SPI with the
BX-24. I've posted a module on my web site at [SPI.sip]:

http://home.comcast.net/~tomhandley/bx-24/bx-24.html

Note, in the example I use the BX-24's LEDs and Output-Capture pins
but you can easily change that in the Module's constant definitions.

- Tom

--- In basicx@basi..., "Paul J. Smith" <pjsmith@m...> wrote:
> Thanks very much for this.
>
> Sorry, but I'm bit of a beginner programming microprocessors like
the
> bx24. I'm using the SPI commands. Can you use the ShiftOut in
> combination with the SPI commands/bus? It looks like a different
method
> of communication to me?
>
> I have the sclk, miso, and mosi pins from the bx24 connected to the
> 1270.
>
> The data sheet for the 1270 does show the data starts on the falling
> edge of the sclk. It starts when it receives the control byte,
starts
> acquisition on the 6th bit. Conversion takes 6 sclk from the 6th
bit of
> the control byte, then you read the result on the next 12 bits.
There
> is a sstrb after the conversion time that takes 2 sclk cycles.
>
> The code I have so far is
>
> Const CSPin as Byte = 13
>
> Sub Max1270()
>
> Dim SPIChannel as Byte
> Dim SPISetupByte as byte
> Dim V as integer
>
> SPISetUpByte = 1
> SPIChannel = 1
> Call OpenSPI(SPIChannel, SPISetUpByte, CSPin)
>
> Dim PutData(1 to 2) as Byte, GetData(1 to 2) as Byte
>
> ' Put control byte
> PutData(1) = bx10000001
> Call SPICmd(SPIChannel, 1, PutData(1), 0, GetData(1))
> ' wait 4 clock cycles
> Call ShiftOut(17, 3, 4, 0)
> ' receive 16 bit result
> Call SPICmd(SPIChannel, 0, PutData(1), 1, GetData(1))
> Call SPICmd(SPIChannel, 0, PutData(1), 1, GetData(2))
>
> ' Put the high and low bytes together. Result is in lower 12-
bits.
> v = CInt(GetData(1)) * 16 + CInt(GetData(2))\16
>
> debug.print cstr(v)
>
> End sub >
> -----Original Message-----
> From: basicx@basi... [mailto:basicx@basi...] On
Behalf
> Of Don Kinzer
> Sent: 24 July 2005 00:47
> To: basicx@basi...
> Subject: [BasicX] Re: bx24 - max1270
>
> --- In basicx@basi..., "Paul J. Smith" <pjsmith@m...> wrote:
> > [...] I don't know how to make the mx24 wait that 4 cycles,
> > which I'm guessing is what the shiftout outputpin, clockpin, msb,
> > [0 \ 4] is for in the above.
>
> The control byte that is specified (10000001) indicates
> that "external clock" mode is being used. That means that the
clock
> output from the BX-24 is used by the MAX1270 for its internal
> timing. All that you need to do is shift out four bits - any four
> bits will do because the MAX1270 ignores them.
>
> Call ShiftOut(dataPin, clkPin, 4, 0)
>
> One other aspect of this that might cause a problem is that the
> PBasic code specifies that when shifting data in the data line
> should be sampled after the clock edge. The BX-24 doesn't support
> this mode - it always samples the data line just before the clock
> edge. That doesn't necessarily mean that you can't make it work.
> Study the timing diagrams in the datasheet and draw yourself some
> diagrams of what you expect the timing from the BX-24 to look like.
>
> Don >
>
> Yahoo! Groups Links




The 2024 Embedded Online Conference