Page 1 of 1

What am I doing wrong?

Posted: Sun Nov 23, 2014 6:40 pm
by gmwow
Hi. Just trying to get SPI working between a pic18f46k20 and a mcp23s17. Right now it's just a simple test program but I just can't get anything to work. I had tried a test program from a forum post on here that was for Flowcode v5 but it didn't work either. The program I'm currently fiddling with is structurally modeled after that one. I've tried extrapolating information out of c code examples but that hasn't helped. I know the hardware is functional because I can program the chip with a demo c program and it works but I don't know enough about programming in c yet to import that functionality into Flowcode so I can use it for the rest of the project. Can anyone lend me a hand?

the datasheet for the mcp23s17 is:
http://ww1.microchip.com/downloads/en/D ... 21952b.pdf

My Flowcode is:
Port Expansion Test v2.fcfx
(12.68 KiB) Downloaded 251 times

Re: What am I doing wrong?

Posted: Mon Nov 24, 2014 5:37 pm
by gmwow
Ok. My o-scope is old and having a bad day but I verified that there is activity on mosi but nothing on miso. I've tried a different mcp23s17 chip so I don't think it's that. The spi slave isn't listening because my program in the PIC isn't talking to it correctly. But What am I doing wrong? I feel like it has to be something stupidly simple and right in front of my nose but I can't see it. Please I need some help guys. This is a work project and my deadline is within touching distance.

Re: What am I doing wrong?

Posted: Tue Nov 25, 2014 12:14 am
by kersing
Looking at your flowchart the only enabled icons are for output, also your port is set to output mode. So I would not expect MISO activity.

Have you checked the console window? The tab 'SPI - Master 1' shows the bytes you are sending on the SPI port. Do they match the demo C code?

Re: What am I doing wrong?

Posted: Sat Nov 29, 2014 12:18 am
by gmwow
Sorry for the late reply, and thank you for the help kersing. It's been a holiday week here in the states so not much time to get any work done. I must have posted the version that I had been fiddling with and left the icons disabled, sorry about that. It doesn't work with them enabled either.
You said I have the port set to output mode. Where do I find and change that in Flowcode 6? I didn't see it listed in the component properties.

Re: What am I doing wrong?

Posted: Sat Nov 29, 2014 10:03 pm
by kersing
It is not in FC6 as such as I was referring to the mcp23s17 port. Looking at the console window during simulation you are setting IODIR to zero which means (data sheet page 12) the direction is output.

Re: What am I doing wrong?

Posted: Sat Nov 29, 2014 11:08 pm
by gmwow
Ok. I see it. I fixed that and still nothing. Though don't I need to address the two ports separately? IODIRA and IODIRB? Is this one more like what you were saying?
Port Expansion Test v3.fcfx
(12.51 KiB) Downloaded 281 times
I'm trying to set port A as output and port B as input. I have some push button switches attached to port B of the mcp and leds attached to port A.

Re: What am I doing wrong?

Posted: Sun Jan 04, 2015 5:49 pm
by Rudi
hi gmwow,

how do you managed the spi message for the mcp23s17?
Send you as Char each or as String?

example

send msg for mcp23S17 Port A bit 0 with value 1
SPI(deviceadress, GPIOA, 0x01)

deviceadress = 0x40...+ your A2 A1 A0
GPIOA = #define GPIOA 0x12
data = 0x01 for 00000001
let bit 0 be high

send msg for mcp23S17 Port A bit 0 with value 0
SPI(deviceadress, GPIOA, 0x00)


how you send the message over spi to the port ?


if you make a makro
example:
init_spi_masterI()
and put all init's in this and call it from main will be friendly to read code

here you can manage then direction, interupt function ( high or low set ) and so on.

my problem is ( i work same just in time )
if i take the spi master - after send a command - the process is frozzen or not go to step 2
if i take the cal spi icon, and try to send with
cal_spi1::Slave_TxByte(1)
the compiler still stop

but the same example in arduino sketch runs perfect. so the hardware is ok.
perhaps we can make together a runing flowchart and a mcp23S17 icon?

can u test the CAL SPI in a empty flowchart, only add icon, try to call a Slave_TxByte with fantasi data 0x00
and compile, did it stop too?
http://www.flowcode.co.uk/mmforums/viewt ... 006#p65358

i work last 3 nights at this but i stopped now - this frusted me

best wishes
rudi ;-)

Re: What am I doing wrong?

Posted: Sun Jan 04, 2015 6:18 pm
by Rudi
after you add SPI_MASTER Icon
be sure, that you change setup follow:

( Standard )
Clock Phase = Leading Edge

change it to
Clock Phase = Trailing Edge
my flowchart now it run like a charme for me

best wishes
rudi ;-)

Re: What am I doing wrong?

Posted: Mon Jan 05, 2015 2:06 pm
by Rudi
http://www.flowcode.co.uk/mmforums/viewt ... 000#p65395
test it, change it and have fun!
rudi ;-)