Bluepill need help with interrupt
Posted: Mon Nov 23, 2020 8:51 pm
Hi all,
Just getting started with the Bluepill, and so far things have been going well. But I've run into a snag with using interrupts.
I have this interfaced to a Sega Genesis console, and what I want is whenever I write to a certain address the byte value is grabbed and sent out to my serial monitor. This works...except the data is always wrong. The timing has to be fast enough to clock the data pin values on the rising edge of the nTIME signal coming from the Genesis. I have this set up as an ISR, but it's still not working. This cartridge has been wired up to an FPGA, and that works so I know the hardware is OK. The Bluepill is the wildcard here, and my coding experience with these is very minimal.
Here is my code so far, just trying with one data pin right now - to see if it's a 0 or 1 based on the 0x00 or 0x01 byte i'm writing with my test ROM game. I'm using software serial as my dedicated serial pins are being used for some of the data pins.
Any help with this rather niche problem would be greatly appreciated!
Just getting started with the Bluepill, and so far things have been going well. But I've run into a snag with using interrupts.
I have this interfaced to a Sega Genesis console, and what I want is whenever I write to a certain address the byte value is grabbed and sent out to my serial monitor. This works...except the data is always wrong. The timing has to be fast enough to clock the data pin values on the rising edge of the nTIME signal coming from the Genesis. I have this set up as an ISR, but it's still not working. This cartridge has been wired up to an FPGA, and that works so I know the hardware is OK. The Bluepill is the wildcard here, and my coding experience with these is very minimal.
Here is my code so far, just trying with one data pin right now - to see if it's a 0 or 1 based on the 0x00 or 0x01 byte i'm writing with my test ROM game. I'm using software serial as my dedicated serial pins are being used for some of the data pins.
Code: Select all
#include <SoftwareSerial.h>
#define RX PB1
#define TX PB0
SoftwareSerial serial(RX, TX);
//nTIME and nWR pins from Genesis
#define nTIME PB15
#define nWR PB2
//data pins from Genesis
#define d0 PA8
#define d1 PA9
#define d2 PA10
#define d3 PA11
#define d4 PA12
#define d5 PB5
#define d6 PB6
#define d7 PB7
bool val;
volatile int notTime;
void setup() {
//start serial
serial.begin(9600);
//set pins for Software Serial communication
pinMode(RX, INPUT);
pinMode(TX, OUTPUT);
//set nWR, nTIME and data pins
pinMode(nTIME, INPUT);
pinMode(nWR, INPUT);
pinMode(d0, INPUT);
pinMode(d1, INPUT);
pinMode(d2, INPUT);
pinMode(d3, INPUT);
pinMode(d4, INPUT);
pinMode(d5, INPUT);
pinMode(d6, INPUT);
pinMode(d7, INPUT);
//use interrupt for nTIME
attachInterrupt(digitalPinToInterrupt(nTIME),time_ISR,RISING);
}
void time_ISR(){
notTime = 0;
}
void loop() {
//set nTIME interrupt high by default - wait for it to trigger
notTime = 1;
while (notTime){
//wait in here until interrupt triggers and boots us out of the while block
}
//as soon as interrupt is triggered, grab bit info from data[0]
val = GPIOA->IDR & 0x0100;
//print info to monitor
serial.println(val);
}