some problems with spi data transmission

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

chipfryer27
Valued Contributor
Valued Contributor
Posts: 663
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: some problems with spi data transmission

Post by chipfryer27 »

Hi

"send_spi_inter_8MGr_positiv_mosi.fcfx" is unlikely to work as shown.

You are using the INT0 interrupt but nothing is connected to it. Also, you only have it enabled for what will only be the briefest period before disabling it again.

When you push your button, you branch and in that branch you enable your interrupt. However the interrupt will only be active until your branch completes as in your next iteration of your loop you will disable it (assuming your button is released). So in reality, you will only jump to your ISR if you get a trigger on INT0 pin at the same time you have the button pushed. It would be luck if you caught a trigger.

Generally speaking you would enable an interrupt outside of your main loop. This frees your main loop to get busy doing something useful. If an interrupt condition occurred, your program would temporarily break from whatever it was doing to process the interrupt before returning to main loop.

I'm not sure why in both charts you are converting your byte to a string before printing on LCD (the warnings are related to the conversion) as you could simply use PrintNumber instead.

Hope this helps.

Regards

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Good afternoon! However, he is not as kind as we would like. Imagine what I've learned! It turns out that the spi master module for sending data also does not work as it should: you cannot adjust the polarity of the synchronization signals in it, you cannot adjust the polarity of the transmitted data, and the worst thing is that the signals are sent so that even if the slave module worked, it would not be able to process the received data, since the cs, clk,mosi signals are not they coincide in time. In the attached pictures you will see.
Attachments
mosi_software.jpg
mosi_software.jpg (57 KiB) Viewed 972 times
clk_software.jpg
clk_software.jpg (57.93 KiB) Viewed 972 times
cs_software.jpg
cs_software.jpg (56.74 KiB) Viewed 972 times

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Good afternoon! You can change their polarity in the program using registers, I edited the original a little bit - I inserted the button and the lcd1602 indicator. But even in it, the signals do not match properly. I tried to set a delay-the cs signal became longer, but the time still does not match "clk" and "mosi".
Attachments
clk_positiv.jpg
clk_positiv.jpg (59.14 KiB) Viewed 971 times
cs.jpg
cs.jpg (56.71 KiB) Viewed 971 times
spi_send.fcfx
(13.34 KiB) Downloaded 30 times

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Good evening! I decided to test the signals using 2 oscilloscope probes. Unfortunately, the signals cs -clk, cs-mosi,clk-mosi did not match.
Attachments
clk and mosi  do not match.jpg
clk and mosi do not match.jpg (70.38 KiB) Viewed 949 times
cs and mosi  do not match.jpg
cs and mosi do not match.jpg (61 KiB) Viewed 949 times
cs and clk  do not match.jpg
cs and clk do not match.jpg (62.13 KiB) Viewed 949 times

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Goodnight! I found a way to fix the signal mismatch -at the end of the program I inserted a small delay of 150 microseconds. Otherwise, the relative position of the clk and mosi pulses can be adjusted by changing the register in the program.
Attachments
clk and mosi  do not match.jpg
clk and mosi do not match.jpg (67.31 KiB) Viewed 929 times
cs and clk is match.jpg
cs and clk is match.jpg (65.81 KiB) Viewed 929 times
spi_send.fcfx
(13.34 KiB) Downloaded 28 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 663
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: some problems with spi data transmission

Post by chipfryer27 »

Hi

I've been busy the last few days and only catching up with things now.

Previously, I documented Master to Slave and also Slave to Master transmission, but this wasn't for your target chips. Since then I found a couple of issues using v8 with your target (Mega8) which seemed to be resolved in v10. Using v10 I documented Master to Slave using an Uno R3 as the slave as this uses a "328" which is close enough to your chip.

Following on from your traces, I put an analyser on the wires to check things and got unexpected results on MISO. Basically no activity at all.

I was pushed for time today so I may have made a mistake somewhere (unlikely as everything I do always works first time :lol: )

When I get a chance I'll recheck things with the analyser and also compare against a different chip.

Regards

chipfryer27
Valued Contributor
Valued Contributor
Posts: 663
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: some problems with spi data transmission

Post by chipfryer27 »

Hi

My traces for Master to Slave were fine and I can send any number of bytes from Master to Slave.

However I'm having issues with Slave to Master. I can't seem to get any activity on the MISO pin. I tried a different target and this just confused things further. The Master SPI component has the MOSI/MISO/CLK/SS pins documented as has the Slave component and I would expect MOSI - MOSI etc when connecting. However when using the PIC I don't receive anything unless I "swap" MOSI/MISO pins so at the Master I connect MOSI pin to the Slave MISO pin. No big deal once you figure it out but confusing none the less.

So far I haven't had any luck in getting any activity on the MISO line (as viewd by Master).

Regards

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Good afternoon! I still have nothing to please you and myself with positive news on receiving spi data. I would like to clarify which programs you used to transmit and send data-the latter using registers? You wrote that you need to connect the mosi output from the master to the miso output for the slave and what did you get? Have you used the indicator to display the received data?

chipfryer27
Valued Contributor
Valued Contributor
Posts: 663
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: some problems with spi data transmission

Post by chipfryer27 »

Hi

When I get a chance I will send over my Tx and Rx (Rx using an Uno R3) and the R3 has no issue in receiving either a byte or an string of bytes.

I only had the crossover issue when using PIC-PIC and is probably just a documentation typo or the like. No big deal once you figure it out.

With SPI, as I understand it, it is always bidirectional in that when the Master provides a clock, data is simultaneously clocked out from the Master register bit-by-bit to Slave and from the Slave register to Master.

As I'm getting no activity on the MISO I think there is an issue in loading the Slave.

Unfortunately I have no access to hardware just now but I'll look into this when I get a chance.

Do note that I did not access registers directly, I only used Flowcode components to Send/Receive.

Regards

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Good afternoon! I do not argue-with the help of the flowcode program components, you can send data-but the adjustments do not work there-you cannot select the polarity, you cannot select the moment of synchronization along the leading or trailing edge, and in a program with registers you can keep all these moments under control.

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Good evening! I almost succeeded. Only there is a small artifact-when the power is connected, a number immediately appears on the indicator of the receiving controller, then you start sending your numbers and they appear. The error was in the program-I changed the connection of the indicator on the board, and changed it in the program from the beginning, and then when I used duplicates of old programs, I forgot what was connected there differently.
Attachments
spi_send_0_255.fcfx
(13.35 KiB) Downloaded 20 times
get_lcd.fcfx
(12.56 KiB) Downloaded 24 times

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Good evening! When you start the data reception program on the second controller, random numbers appear on the screen, even if you did not send anything. To get rid of this effect, it is enough to connect the reset button and, if any numbers appear, restart the program before the start of data transmission and reception. Or make a subroutine in the receiving controller, which, after pressing the button, would fill the screen of the receiving indicator with some signs, and then be cleared.
I would like to thank chipfryer27 separately for the help and support and that he did not run out of patience :D

chipfryer27
Valued Contributor
Valued Contributor
Posts: 663
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: some problems with spi data transmission

Post by chipfryer27 »

Hi

I've been a bit quiet recently due to being quite tied up at work and setting up a new laptop.

I should be caught up by the weekend.

Regards

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Good afternoon! You once wrote that you are doing well. I would like to ask you to help me figure out another technical problem. Do you need to write this or create a new topic?

chipfryer27
Valued Contributor
Valued Contributor
Posts: 663
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: some problems with spi data transmission

Post by chipfryer27 »

Hi

Happy to help whenever and if I can.

If it's a new topic then please post a new message as that way more people are likely to read and help.

Regards

gilanetugila
Posts: 155
Joined: Thu Jul 30, 2020 2:01 pm
Has thanked: 7 times
Contact:

Re: some problems with spi data transmission

Post by gilanetugila »

Good evening! Here is a link to an old problem that I do not know how to solve. https://www.matrixtsl.com/mmforums/view ... 05#p108205

Post Reply