some problems with spi data transmission
Moderator: Benj
-
- Valued Contributor
- Posts: 784
- Joined: Fri Jun 06, 2014 3:53 pm
- Has thanked: 186 times
- Been thanked: 205 times
Re: some problems with spi data transmission
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
"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
-
- Posts: 268
- Joined: Thu Jul 30, 2020 2:01 pm
- Has thanked: 7 times
- Been thanked: 1 time
Re: some problems with spi data transmission
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 (57 KiB) Viewed 4124 times
-
- clk_software.jpg (57.93 KiB) Viewed 4124 times
-
- cs_software.jpg (56.74 KiB) Viewed 4124 times
-
- Posts: 268
- Joined: Thu Jul 30, 2020 2:01 pm
- Has thanked: 7 times
- Been thanked: 1 time
Re: some problems with spi data transmission
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 (59.14 KiB) Viewed 4123 times
-
- cs.jpg (56.71 KiB) Viewed 4123 times
-
- spi_send.fcfx
- (13.34 KiB) Downloaded 124 times
-
- Posts: 268
- Joined: Thu Jul 30, 2020 2:01 pm
- Has thanked: 7 times
- Been thanked: 1 time
Re: some problems with spi data transmission
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 (70.38 KiB) Viewed 4101 times
-
- cs and mosi do not match.jpg (61 KiB) Viewed 4101 times
-
- cs and clk do not match.jpg (62.13 KiB) Viewed 4101 times
-
- Posts: 268
- Joined: Thu Jul 30, 2020 2:01 pm
- Has thanked: 7 times
- Been thanked: 1 time
Re: some problems with spi data transmission
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 (67.31 KiB) Viewed 4081 times
-
- cs and clk is match.jpg (65.81 KiB) Viewed 4081 times
-
- spi_send.fcfx
- (13.34 KiB) Downloaded 98 times
-
- Valued Contributor
- Posts: 784
- Joined: Fri Jun 06, 2014 3:53 pm
- Has thanked: 186 times
- Been thanked: 205 times
Re: some problems with spi data transmission
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 )
When I get a chance I'll recheck things with the analyser and also compare against a different chip.
Regards
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 )
When I get a chance I'll recheck things with the analyser and also compare against a different chip.
Regards
-
- Valued Contributor
- Posts: 784
- Joined: Fri Jun 06, 2014 3:53 pm
- Has thanked: 186 times
- Been thanked: 205 times
Re: some problems with spi data transmission
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
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
-
- Posts: 268
- Joined: Thu Jul 30, 2020 2:01 pm
- Has thanked: 7 times
- Been thanked: 1 time
Re: some problems with spi data transmission
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?
-
- Valued Contributor
- Posts: 784
- Joined: Fri Jun 06, 2014 3:53 pm
- Has thanked: 186 times
- Been thanked: 205 times
Re: some problems with spi data transmission
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
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
-
- Posts: 268
- Joined: Thu Jul 30, 2020 2:01 pm
- Has thanked: 7 times
- Been thanked: 1 time
Re: some problems with spi data transmission
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.
-
- Posts: 268
- Joined: Thu Jul 30, 2020 2:01 pm
- Has thanked: 7 times
- Been thanked: 1 time
Re: some problems with spi data transmission
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 143 times
-
- get_lcd.fcfx
- (12.56 KiB) Downloaded 127 times
-
- Posts: 268
- Joined: Thu Jul 30, 2020 2:01 pm
- Has thanked: 7 times
- Been thanked: 1 time
Re: some problems with spi data transmission
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
I would like to thank chipfryer27 separately for the help and support and that he did not run out of patience
-
- Valued Contributor
- Posts: 784
- Joined: Fri Jun 06, 2014 3:53 pm
- Has thanked: 186 times
- Been thanked: 205 times
Re: some problems with spi data transmission
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
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
-
- Posts: 268
- Joined: Thu Jul 30, 2020 2:01 pm
- Has thanked: 7 times
- Been thanked: 1 time
Re: some problems with spi data transmission
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?
-
- Valued Contributor
- Posts: 784
- Joined: Fri Jun 06, 2014 3:53 pm
- Has thanked: 186 times
- Been thanked: 205 times
Re: some problems with spi data transmission
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
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
-
- Posts: 268
- Joined: Thu Jul 30, 2020 2:01 pm
- Has thanked: 7 times
- Been thanked: 1 time
Re: some problems with spi data transmission
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
-
- Valued Contributor
- Posts: 784
- Joined: Fri Jun 06, 2014 3:53 pm
- Has thanked: 186 times
- Been thanked: 205 times
Re: some problems with spi data transmission
Hi
For those reading the above, the following link may be of help regarding SPI Slave using Arduino.
https://www.flowcode.co.uk/forums/viewtopic.php?t=2768
Regards
For those reading the above, the following link may be of help regarding SPI Slave using Arduino.
https://www.flowcode.co.uk/forums/viewtopic.php?t=2768
Regards